如何检测完整版本的浏览器?

时间:2018-11-27 10:01:59

标签: javascript html internet-explorer browser

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

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

1 个答案:

答案 0 :(得分:0)

如果可以使用第三方JS库,则可以尝试使用平台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>

通过各种浏览器输出。

enter image description here