Last active
July 24, 2018 09:33
-
-
Save capJavert/a23440311c02915f722c493e540fc14a to your computer and use it in GitHub Desktop.
Detect browser type
This file contains hidden or 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
var BrowserEnum = Object.freeze({ | |
chrome: 'CHROME_BROWSER', | |
firefox: 'FIREFOX_BROWSER', | |
opera: 'OPERA_BROWSER', | |
safari: 'SAFARI_BROWSER', | |
ie: 'SHIT_BROWSER', | |
edge: 'EDGE_BROWSER' | |
}); | |
var whichBrowser = function() { | |
if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { | |
return BrowserEnum.opera; | |
} | |
if(typeof InstallTrigger !== 'undefined') { | |
return BrowserEnum.firefox; | |
} | |
if(!!window.chrome && !!window.chrome.webstore) { | |
return BrowserEnum.chrome; | |
} | |
if(/constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification)) { | |
return BrowserEnum.safari | |
} | |
if(/*@cc_on!@*/false || !!document.documentMode) { | |
return BrowserEnum.ie | |
} | |
if(!isIE && !!window.StyleMedia) { | |
return BrowserEnum.edge | |
} | |
// other | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment