使用 JavaScript 检测 Windows 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4006420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect Windows Version With JavaScript
提问by reefine
Specifically, I am trying to detect Windows XP users as they are not compatible with my software.
具体来说,我试图检测 Windows XP 用户,因为他们与我的软件不兼容。
Is there a way to detect with at least 70% or higher accuracy?
有没有办法以至少 70% 或更高的准确度进行检测?
回答by ?ime Vidas
Try navigator.appVersion
尝试 navigator.appVersion
http://msdn.microsoft.com/en-us/library/ms533080(v=VS.85).aspx
https://developer.mozilla.org/en/DOM/window.navigator.appVersion
http://msdn.microsoft.com/en-us/library/ms533080(v=VS.85).aspx
https://developer.mozilla.org/en/DOM/window.navigator.appVersion
I have Windows 7 here and the navigator.appVersion
returns a string containing "NT 6.1" in these browsers: Chrome, Opera, Safari, IE9 beta.
我这里有 Windows 7,navigator.appVersion
在这些浏览器中返回一个包含“NT 6.1”的字符串:Chrome、Opera、Safari、IE9 beta。
Only Firefox does not return that info in that string :(
只有 Firefox 不会在该字符串中返回该信息:(
btw, WinXP is "NT 5.1", Vista is "NT 6.0" ...
顺便说一句,WinXP 是“NT 5.1”,Vista 是“NT 6.0”...
Update
更新
navigator.userAgent
returns the "NT version" string in all 5 browsers. That means that userAgent
is the property that is able to tell the Windows version.
navigator.userAgent
在所有 5 个浏览器中返回“NT 版本”字符串。这意味着这userAgent
是能够告诉 Windows 版本的属性。
回答by Tim ?as
It appears that you can use the navigator
host object:
看来您可以使用navigator
主机对象:
var os = navigator.platform
See here for more info: http://www.jguru.com/faq/view.jsp?EID=1100686
请参阅此处了解更多信息:http: //www.jguru.com/faq/view.jsp?EID= 1100686
回答by John Doe
window.navigator.appVersion.split("NT")[1].split(";")[0].trim()
Will return the Windows version.
将返回 Windows 版本。