Last active
January 24, 2020 06:32
-
-
Save ziqq/51536afab76f732514536c1059dbcd9a to your computer and use it in GitHub Desktop.
Test browser type
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
function _detectBrowserType() { | |
const html = document.querySelector('html'); | |
const isChrome = !!window.chrome && !isOpera; | |
const isFirefox = typeof window.InstallTrigger !== 'undefined'; | |
const userAgent = navigator.userAgent || navigator.vendor || window.opera; | |
const isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | |
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); | |
const isExplorer = typeof document !== 'undefined' && !!document.documentMode && !isEdge; | |
// if (/windows phone/i.test(userAgent)) { | |
// html.classList.add('is-windows'); | |
// } | |
if (/android/i.test(userAgent)) { | |
html.classList.add('is-android'); | |
} else { | |
html.classList.remove('is-android'); | |
} | |
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { | |
html.classList.add('is-ios'); | |
} else { | |
html.classList.remove('is-ios'); | |
} | |
if (isChrome) { | |
html.classList.add('is-chrome'); | |
html.classList.remove('is-safari'); | |
html.classList.remove('is-firefox'); | |
} else if (isSafari) { | |
html.classList.add('is-safari'); | |
html.classList.remove('is-chrome'); | |
html.classList.remove('is-firefox'); | |
} else if (isFirefox) { | |
html.classList.add('is-firefox'); | |
html.classList.remove('is-chrome'); | |
html.classList.remove('is-safari'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment