【问题标题】:How can you detect the full version of a browser?如何检测浏览器的完整版本?
【发布时间】:2019-04-29 01:01:45
【问题描述】:

我发现代码检测浏览器和版本,但我正在搜索完整版

Example :

navigator.sayswho= (function(){
    var ua= navigator.userAgent, tem, 
    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] || '' || tem[2]);
    }
    if(M[1]=== 'Chrome'){
        tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
        console.log("eee",tem);
        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], tem[2]);
    return M.join(' ');
})();

console.log("ddddd",navigator.sayswho);  

使用上述代码浏览器和版本获取,但不是完整版。

Chrome 70

IE 11 

how to get full version like 

Chrome 70.0.3538.102

IE 11.726.16299.0

【问题讨论】:

标签: javascript html internet-explorer browser


【解决方案1】:

如果您可以使用第三方 JS 库,则可以尝试使用 Platform JS 进行测试。

示例代码:

<!doctype html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/platform/1.3.5/platform.min.js"></script>

<script>
console.log(platform);
document.write("You are using " + platform.name +
               " v" + platform.version + 
               " on " + platform.os);
</script>
</head>
<body>
</body>
</html>

各种浏览器的输出。

【讨论】:

  • 对于其他浏览器,它会获得完整版本。对于 IE,它只获得版本 (IE11.0) 期望 IE 11.0.9256
  • @John Ken,我用其他 JS 库进行了测试,但没有任何库返回完整版本的 IE。
猜你喜欢
  • 2011-08-20
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 2011-03-10
  • 2014-12-28
  • 1970-01-01
  • 2011-08-12
  • 1970-01-01
相关资源
最近更新 更多