admin管理员组文章数量:1315851
As latest version of Microsoft Edge is out and uses Blink - what is the correct way to differentiate Old Edge from New Edge one with javascript?
Currently I plan to look into navigator.userAgent
to check for older versions of Edge (up to 18)
const isOldEdge = /edge\/([0-1][0-8]|[0-9]\D)/.test(navigator.userAgent.toLowerCase());
Is this correct way to detect it?
As latest version of Microsoft Edge is out and uses Blink - what is the correct way to differentiate Old Edge from New Edge one with javascript?
Currently I plan to look into navigator.userAgent
to check for older versions of Edge (up to 18)
const isOldEdge = /edge\/([0-1][0-8]|[0-9]\D)/.test(navigator.userAgent.toLowerCase());
Is this correct way to detect it?
Share Improve this question edited Feb 17, 2020 at 20:22 godblessstrawberry asked Feb 12, 2020 at 9:41 godblessstrawberrygodblessstrawberry 5,0884 gold badges44 silver badges69 bronze badges 7- 5 It is usually better to detect features instead of versions. What are you trying to achieve with that? – str Commented Feb 12, 2020 at 10:28
-
currently I'm styling html5 range input that has gradient track and
Old Edge
requires another approach as it doesn't allow to style the full track (only separate parts before and after thumb). not sure how to test this feature – godblessstrawberry Commented Feb 12, 2020 at 10:45 - You can probably test that with CSS feature queries. – str Commented Feb 12, 2020 at 11:04
-
@str I need to test for selectors
::-ms-fill-lower {...}
&::-ms-fill-upper
, not features - I dont think this will help here. I can test for specific features support to determine I'm in Old Edge but that seems to be less obvious and more fragile – godblessstrawberry Commented Feb 12, 2020 at 12:43 - For that you could use a linear gradient that "moves" based on the current range input value. That would work cross-browser, including old versions of Edge. – str Commented Feb 12, 2020 at 14:20
1 Answer
Reset to default 8I suggest you use window.navigator userAgent to check whether the browser is Microsoft Chromium Edge or MS edge (EdgeHtml).
The Edge (EdgeHtml) browser userAgent:
mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/70.0.3538.102 safari/537.36 edge/18.18362
The Microsoft Chromium Edge userAgent:
mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/80.0.3987.87 safari/537.36 edg/80.0.361.50
Sample code:
<!doctype html>
<html>
<head>
<title>Test demo</title>
</head>
<body>
<script>
var browser = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge (EdgeHtml)";
case agent.indexOf("edg") > -1: return "MS Edge Chromium";
case agent.indexOf("opr") > -1 && !!window.opr: return "opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome";
case agent.indexOf("trident") > -1: return "Internet Explorer";
case agent.indexOf("firefox") > -1: return "firefox";
case agent.indexOf("safari") > -1: return "safari";
default: return "other";
}
})(window.navigator.userAgent.toLowerCase());
document.body.innerHTML = "This is " + browser + " browser." + "<br><br>" + window.navigator.userAgent.toLowerCase();
</script>
</body>
</html>
Output in MS edge (EdgeHtml) browser:
Output in MS edge Chromium browser:
Reference:
How to detect Microsoft Chromium Edge (chredge , edgium) in Javascript
本文标签: What is the correct way to detect new Microsoft Edge v80 (Blink) via JavascriptStack Overflow
版权声明:本文标题:What is the correct way to detect new Microsoft Edge v80 (Blink) via Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985820a2408669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论