JavaScript - 获取有关浏览器的详细信息 [英] JavaScript - get detailed information about the browser

查看:94
本文介绍了JavaScript - 获取有关浏览器的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我正在寻找能让我轻松访问 useragentstring.com 等信息的东西,但在JS中,没有我解析用户代理并查找每个可能的文本位。对象可能是这样的:

Basically I'm looking for something to give me easy access to information like useragentstring.com, but in JS, without me parsing the user agent and looking for each possible bit of text. The object could be something like this:

browser      = UserAgent.Browser;                // Chrome
browserVer   = UserAgent.BrowserVersion;         // 5.0.342.9
os           = UserAgent.OperatingSystem;        // Windows NT
osVer        = UserAgent.OperatingSystemVersion; // 6.1
layoutEng    = UserAgent.LayoutEngine;           // WebKit
layoutEngVer = UserAgent.LayoutEngineVersion;    // 533.2

是否存在类似的东西或我是否必须自己写一个?编写另一个用户代理解析器似乎并不容易,所有这些模仿都可以追溯到网络的黑暗时代。

Does something similar to that exist or do I have to write one myself? Writing yet another user agent parser doesn't seem that easy with all those impersonations going back to the dark ages of the web.

具体来说,我正在寻找的东西不是只是将用户代理分成几部分并交给我,因为这与用户代理本身一样无用;相反,它应解析用户代理并识别引擎,浏览器,操作系统等,并仅返回具体部分,如示例所示。

Specifically I'm looking for something that doesn't just split the user agent into parts and give them to me, because that's as useless as the user agent itself; instead it should parse the user agent and recognize the engine, browser, OS, etc. and return the concrete parts only, as in the example.

推荐答案

这应该对你有帮助,看看下面的值:

This should help you, have a look of the values for the following:

navigator["appCodeName"]
navigator["appName"]
navigator["appMinorVersion"]
navigator["cpuClass"]
navigator["platform"]
navigator["plugins"]
navigator["opsProfile"]
navigator["userProfile"]
navigator["systemLanguage"]
navigator["userLanguage"]
navigator["appVersion"]
navigator["userAgent"]
navigator["onLine"]
navigator["cookieEnabled"]
navigator["mimeTypes"]

var x = '';
for(var p in navigator){
   try {
      x += p + '=' + navigator[p] + "\n";
      console.log(x);
   }
   catch(e) {
       console.error(e);
   }
}

这篇关于JavaScript - 获取有关浏览器的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆