且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用javascript定位Windows 10 Edge浏览器

更新时间:2022-10-16 16:23:00

尝试检测功能而不是特定的浏览器。它更具有前瞻性。您很少使用浏览器检测。

这样就可以了:一个选项是使用库(用户代理字符串有很多复杂性) ),或者手动解析 window.navigator.userAgent

With that out of the way: one option is to use a library (there are many intricacies to User Agent strings), or alternatively to parse window.navigator.userAgent manually.

使用解析器库

# https://github.com/faisalman/ua-parser-js.

var parser = new UAParser();
var result = parser.getResult();

var name = result.browser.name;
var version = result.browser.version;

使用Javascript的原始方法

# Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) \
# Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

window.navigator.userAgent.indexOf("Edge") > -1