问题
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 version etc.
I thought to read user agent from Services.appShell.hiddenDOMWindow
and window.navigator
but on browser startup hiddenDOMWindow
isn't loaded yet.
Right now I can only get WINNT
from:
Components.utils.import("resource://gre/modules/osfile.jsm")
console.log(OS.Constants.Sys.Name)
or
console.log(Services.appinfo.OS)
console.log
of window.navigator
gives all this good stuff, how to get this without having access to 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
回答1:
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
)
回答2:
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 WinXPvar 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
来源:https://stackoverflow.com/questions/24032279/get-specifics-about-operating-system