用javascript浏览器识别

时间:2016-04-03 14:54:33

标签: javascript browser

我正在创建一个网页,我正在使用此代码来检测浏览器细节,例如版本和名称。

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] || '');
    }
    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(' ');
})();

此处的代码:How can you detect the version of a browser?

我想知道这是做什么的。如果用户使用Chrome,那么mu文件系统中的哪个文件会打开以阅读浏览器细节?

1 个答案:

答案 0 :(得分:1)

navigator属性位于窗口界面上,是浏览器中的标准只读界面。

请查看此处的规范:https://www.w3.org/TR/html5/webappapis.html#navigator

  

Window接口的navigator属性必须返回Navigator接口的一个实例,它表示用户代理(客户端)的身份和状态,并允许Web页面将自己注册为潜在的协议和内容处理程序: