Skip to content

Instantly share code, notes, and snippets.

@nola
Created December 16, 2013 20:03
Show Gist options
  • Select an option

  • Save nola/7993391 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7993391 to your computer and use it in GitHub Desktop.
// this targets Google Chrome and Opera 18+
var isChromium = window.chrome;
if(isChrome === true) {
// is chromium based browser
} else {
// not chromium based browser
}
//To target if the browser is Google Chrome, use this:
var isChromium = window.chrome,
vendorName = window.navigator.vendor;
if(isChromium === true && vendorName === "Google Inc.") {
// is Google chrome
} else {
// not Google chrome
}
//To target if the browser is Opera 18 or above:
var isChromium = window.chrome,
vendorName = window.navigator.vendor;
if(isChromium === true && vendorName === "Opera Software ASA") {
// is Opera 18 or above
} else {
// not Opera 18 or above
}
//Checking if Firefox:
// check if Firefox
var FF = !(window.mozInnerScreenX == null);
if(FF) {
// is firefox
} else {
// not firefox
}
//Checking if IE and IE versions:
// check if IE8-11
var hasDocumentMode = (document.documentMode !== undefined),
isIE8 = (isDocumentMode === 8),
isIE9 = (isDocumentMode === 9),
isIE10 = (isDocumentMode === 10),
isIE11 = (isDocumentMode === 11);
if(hasDocumentMode) {
if(isIE11){
// browser is IE11
} else if(isIE10){
// browser is IE10
} else if(isIE9){
// browser is IE9
} else if(isIE8){
// browser is IE8
}
}
//If you really need to detect IE7, check for document.attachEvent:
// check if IE7
var isIE7 = (document.attachEvent !== undefined);
if(isIE7) {
// browser is IE7
} else {
// browser NOT IE7
}
//Checking for Touch support:
// check if browser has touch support
var hasTouch = !!("undefined" != typeof document.documentElement.ontouchstart);
if (hasTouch) {
// has touch support
} else {
// does NOT have touch support
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment