Skip to content

Instantly share code, notes, and snippets.

@barlas
Last active August 29, 2015 14:12
Show Gist options
  • Save barlas/aa26f425a582e5ce75dc to your computer and use it in GitHub Desktop.
Save barlas/aa26f425a582e5ce75dc to your computer and use it in GitHub Desktop.
javascript - Browser and Device detection variables.
var isChrome = navigator.userAgent.indexOf('Chrome') > -1,
isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1,
isSafari = navigator.userAgent.indexOf('Safari') > -1,
isIE = navigator.appName.indexOf('Internet Explorer')!=-1,
isIE7 = navigator.appVersion.indexOf("MSIE 7.") != -1,
isIE8 = navigator.appVersion.indexOf("MSIE 8.") != -1;
if ((isChrome)&&(isSafari)) {isSafari=false;}
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isTabletMobile = true : isTabletMobile = false;
/iPad/i.test(navigator.userAgent) ? isTablet = true : isTablet = false;
/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isMobile = true : isMobile = false;
/Android/i.test(navigator.userAgent) ? isAndroid = true : isAndroid = false;
// Sample usage:
if ( isTabletMobile ) {
// some code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment