如何检测浏览器的版本? [英] How can you detect the version of a browser?
本文介绍了如何检测浏览器的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找可以让我检测访问该网站的用户使用的是 Firefox 3 还是 4 的代码.我找到的只是用于检测浏览器类型而不是版本的代码.
I've been searching around for code that would let me detect if the user visiting the website has Firefox 3 or 4. All I have found is code to detect the type of browser but not the version.
如何检测这样的浏览器版本?
How can I detect the version of a browser like this?
推荐答案
您可以看到浏览器说了什么,并使用该信息记录或测试多个浏览器.
You can see what the browser says, and use that information for logging or testing multiple browsers.
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= /rv[ :]+(d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome'){
tem= ua.match(/(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`
这篇关于如何检测浏览器的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文