gpt4 book ai didi

javascript - 如何检测浏览器的版本?

转载 作者:IT老高 更新时间:2023-10-28 13:12:06 27 4
gpt4 key购买 nike

我一直在寻找可以让我检测访问该网站的用户是否使用 Firefox 3 或 4 的代码。我发现的只是检测浏览器类型而不是版本的代码。

如何检测这样的浏览器版本?

最佳答案

您可以查看浏览器说什么,并使用该信息记录或测试多个浏览器。

navigator.sayswho= (function(){
var ua= navigator.userAgent;
var tem;
var M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
return M.join(' ');
})();

console.log(navigator.sayswho); // outputs: `Chrome 62`

关于javascript - 如何检测浏览器的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5916900/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com