Skip to content

Instantly share code, notes, and snippets.

@droid001
Created March 14, 2016 09:34
Show Gist options
  • Save droid001/9a9c40cd0518b87f2c65 to your computer and use it in GitHub Desktop.
Save droid001/9a9c40cd0518b87f2c65 to your computer and use it in GitHub Desktop.
Brwoser detection through duck typing
// From http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// At least Safari 3+: "[object HTMLElementConstructor]"
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment