更新时间:2022-05-21 09:43:44
尝试检测功能而不是特定的浏览器.更具前瞻性.很少使用浏览器检测.
顺便说一句:一种选择是使用库(用户代理字符串有很多复杂性),或者手动解析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;
使用Java的原始方法
# 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