【问题标题】:Get specifics about operating system获取有关操作系统的详细信息
【发布时间】:2014-07-24 19:10:31
【问题描述】:

我以为这很容易,但我想不通。

如何判断使用的是Win7还是WinXP?就像操作系统的细节一样。 Linux 应该给出细节。 Mac OS 版本等

我想从Services.appShell.hiddenDOMWindowwindow.navigator 读取用户代理,但在浏览器启动时hiddenDOMWindow 尚未加载。

目前我只能从以下地址获取WINNT

Components.utils.import("resource://gre/modules/osfile.jsm")
console.log(OS.Constants.Sys.Name)

console.log(Services.appinfo.OS)

console.log of window.navigator 提供了所有这些好东西,如何在没有访问window 的情况下获得这些?

appCodeName:"Mozilla"
appName:"Netscape"
appVersion:"5.0 (Windows)"
battery:BatteryManager
buildID:"20140529161749"
cookieEnabled:true
doNotTrack:"yes"
geolocation:Geolocation
language:"en-US"
mimeTypes:MimeTypeArray
mozAlarms:null
mozApps:XPCWrappedNative_NoHelper
mozCameras:CameraManager
mozConnection:MozConnection
mozContacts:ContactManager
mozId:null
mozKeyboard:XPCWrappedNative_NoHelper
mozPay:null
mozPermissionSettings:null
mozPhoneNumberService:PhoneNumberService
mozPower:MozPowerManager
mozTCPSocket:null
onLine:true
oscpu:"Windows NT 5.1"
platform:"Win32"
plugins:PluginArray
product:"Gecko"
productSub:"20100101"
userAgent:"Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0"
vendor:""
vendorSub:""
__proto__:NavigatorPrototype

【问题讨论】:

    标签: operating-system firefox-addon platform


    【解决方案1】:

    您可以使用系统信息服务。获取操作系统版本

    Services.sysinfo.getProperty("version");
    

    请咨询sources 以了解支持的属性。还要注意它们特定于平台的含义(例如,在 Android 上,有 versionkernel_version

    【讨论】:

    【解决方案2】:

    我发现的其他一些方法是:

    • 然后在此处查看维基百科以获取 Windows 版本。 Wikipedia Windows Versions 如果是 NT 5.1 则不是 WinXP

      var os_string = Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).oscpu; //this is something like `Windows NT 6.3; WOW64` and you look for 6.3 which means Windows 8.1
      

    编辑

    刚刚发现Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler)userAgent,就像上面的导航器一样。

    所以就这样吧:

    Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).userAgent 它给你Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0,就像navigator.userAgent一样。

    这是Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler) 中的所有内容:

    appName:"Mozilla"
    appVersion:"5.0"
    defaultPort:80
    misc:"rv:33.0"
    oscpu:"Windows NT 6.3; WOW64"
    platform:"Windows"
    protocolFlags:76
    scheme:"http"
    userAgent:"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
    

    对于 mac,您的 useragent 行和 oscpu 行将告诉您有关操作系统的所有信息。 例如,在 Mac OS X 10.9 上,它会输出Intel Mac OS X 10.9。很高兴你得到了 10.X

    Services.sysinfo.getProperty("version"); 在 OSX 10.9 和 OSX 10.10.1 上输出 13.4.0,在 OSX 10.10.1 上输出 14.0.0,所以对于 mac 来说可能不是一个准确的方法,但它对 windows 有好处。对于 10.10.1,useragent oscpu 只是 10.10 它不显示 .1

    【讨论】:

    • 注意:navigator.platformCc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).platform 不同,第一个返回 Win32,第二个返回 Windows。在 mac 上,第一个返回 MacIntel 第二个返回 Macintosh
    猜你喜欢
    • 2010-11-27
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2012-03-19
    • 2015-10-10
    相关资源
    最近更新 更多