Created
August 26, 2020 18:27
-
-
Save hperantunes/0f976b922d8e566bb06f4f297889f23f to your computer and use it in GitHub Desktop.
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
// 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 - 79 | |
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime); | |
// Edge (based on chromium) detection | |
var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1); | |
// Blink engine detection | |
var isBlink = (isChrome || isOpera) && !!window.CSS; | |
var output = 'Detecting browsers by ducktyping:<hr>'; | |
output += 'isFirefox: ' + isFirefox + '<br>'; | |
output += 'isChrome: ' + isChrome + '<br>'; | |
output += 'isSafari: ' + isSafari + '<br>'; | |
output += 'isOpera: ' + isOpera + '<br>'; | |
output += 'isIE: ' + isIE + '<br>'; | |
output += 'isEdge: ' + isEdge + '<br>'; | |
output += 'isEdgeChromium: ' + isEdgeChromium + '<br>'; | |
output += 'isBlink: ' + isBlink + '<br>'; | |
document.body.innerHTML = output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment