Last active
July 31, 2020 07:40
-
-
Save iamdevlinph/409807abc775172f059ca71f18b9ac4e to your computer and use it in GitHub Desktop.
Check Browser
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/a/56361977/4110257 | |
function name() { | |
var agent = window.navigator.userAgent.toLowerCase(); | |
switch (true) { | |
case agent.indexOf("edge") > -1: return "edge"; | |
case agent.indexOf("edg") > -1: return "chromium based edge (dev or canary)"; | |
case agent.indexOf("opr") > -1 && !!window.opr: return "opera"; | |
case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome"; | |
case agent.indexOf("trident") > -1: return "ie"; | |
case agent.indexOf("firefox") > -1: return "firefox"; | |
case agent.indexOf("safari") > -1: return "safari"; | |
default: return "other"; | |
} | |
} | |
// function name() { | |
// var browserName = ''; | |
// var userAgent = navigator.userAgent; | |
// (typeof InstallTrigger !== 'undefined') && (browserName = 'Firefox'); | |
// ( /* @cc_on!@*/ false || !!document.documentMode) && (browserName = 'IE'); | |
// (!!window.chrome && userAgent.match(/OPR/)) && (browserName = 'Opera'); | |
// (!!window.chrome && userAgent.match(/Edge/)) && (browserName = 'Edge'); | |
// (!!window.chrome && !userAgent.match(/(OPR|Edge)/)) && (browserName = 'Chrome'); | |
// /** | |
// * Expected returns | |
// * Firefox, Opera, Edge, Chrome | |
// */ | |
// return browserName; | |
// } |
Updated code for browser checking using the versions above
https://jsfiddle.net/iamdevlinph/thxkdzbn/6/
Working versions:
Firefox - 78.0.2 (64-bit) (detected as firefox)
Chrome - Version 84.0.4147.105 (Official Build) (64-bit) (detected as chrome)
Opera - 70.0.3728.71 (detected as opera)
New Edge Chromium - Version 84.0.522.44 (Official build) (64-bit) (detected as chromium based edge (dev or canary))
Old Edge - Microsoft Edge 44.19041.1.0 (detected as edge)
IE - 11.388.19041.0 (version downgraded but jsfiddle does not run anymore but detected as ie)
Safari - Version 13.1.1 (14609.2.9.1.3) (detected as safari)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of 28-July-2020
Working versions:
Firefox - 78.0.2 (64-bit) (detected as Firefox)
Chrome - Version 84.0.4147.105 (Official Build) (64-bit) (detected as Chrome)
Opera - 70.0.3728.71 (detected as Opera)
New Edge Chromium - Version 84.0.522.44 (Official build) (64-bit) (detected as Chrome)
Old Edge - Microsoft Edge 44.19041.1.0 (detected as Edge)
IE - 11.388.19041.0 (version downgraded but jsfiddle does not run anymore but detected as IE)
Fiddle: https://jsfiddle.net/iamdevlinph/1gLxbb6s/30/