Created
September 14, 2018 20:37
-
-
Save hitswa/bec2068c6d4600c1c9a13e6f1da8bc27 to your computer and use it in GitHub Desktop.
detect browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// method one https://stackoverflow.com/revisions/9851769/1 | |
var isOpera = !!(window.opera && window.opera.version); // Opera 8.0+ | |
var isFirefox = testCSS('MozBoxSizing'); // FF 0.8+ | |
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; | |
// At least Safari 3+: "[object HTMLElementConstructor]" | |
var isChrome = !isSafari && testCSS('WebkitTransform'); // Chrome 1+ | |
var isIE = /*@cc_on!@*/false || testCSS('msTransform'); // At least IE6 | |
function testCSS(prop) { | |
return prop in document.documentElement.style; | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// method two https://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'; | |
// Safari 3.0+ "[object HTMLElementConstructor]" | |
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification)); | |
// 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