我正在创建一个网页,并使用此代码来检测浏览器的具体信息,例如版本和名称。
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,javascript 将打开 mu 文件系统中的哪个文件来读取浏览器详细信息?
最佳答案
导航器属性位于窗口界面上,是浏览器中的标准只读界面。
查看此处的规范:https://www.w3.org/TR/html5/webappapis.html#navigator
The navigator attribute of the Window interface must return an instance of the Navigator interface, which represents the identity and state of the user agent (the client), and allows Web pages to register themselves as potential protocol and content handlers:
关于javascript - 使用 javascript 识别浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36386971/