Skip to content

Instantly share code, notes, and snippets.

@stereokai
Last active May 1, 2020 19:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stereokai/8b187d74ba773eba0d12 to your computer and use it in GitHub Desktop.
Save stereokai/8b187d74ba773eba0d12 to your computer and use it in GitHub Desktop.
Real, precise, futureproof javascript browser detection
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
isFirefox = typeof InstallTrigger !== 'undefined';
// At least Safari 3+: "[object HTMLElementConstructor]"
isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least IE6
isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge
isEdge = !!window.MSAssertion;
// Chrome 1+
isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink
isBlink = (isChrome || isOpera) && !!window.CSS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment