Get specifics about operating system

前端 未结 2 1044
走了就别回头了
走了就别回头了 2021-01-06 20:22

I thought this would be easy but I can\'t figure this out.

How to tell if using Win7 or WinXP? Like details on operating system. Linux should give specifics. Mac OS

相关标签:
2条回答
  • 2021-01-06 20:54

    You can use the system info service. To get the OS version

    Services.sysinfo.getProperty("version");
    

    Consult the sources for the properties supported. Also pay attention to their platform-specific meaning (e.g. on Android there is version and kernel_version)

    0 讨论(0)
  • 2021-01-06 21:00

    Some other ways I found to do this are:

    • Then check wikipedia here for windows version. Wikipedia Windows Versions If it's NT 5.1 than it's 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
      

    EDIT

    Just discovered that Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler) has the userAgent just like navigator above.

    So just go like:

    Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).userAgent and it gives you Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0 just like navigator.userAgent.

    Here is all that is in 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"
    

    For mac your useragent line and oscpu line will tell you all about the operating system. For example on Mac OS X 10.9 it spts out Intel Mac OS X 10.9. It's nice you get the 10.X

    Services.sysinfo.getProperty("version"); puts out 13.4.0 on OSX 10.9 and on OSX 10.10.1 it puts out 14.0.0 so probably not an accurate way for mac, but its good for windows. For 10.10.1 the useragent oscpu is just 10.10 it doesnt show the .1

    0 讨论(0)
提交回复
热议问题