使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:06:52  来源:igfitidea点击:

Detect Windows Version With JavaScript

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.appVersionreturns 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.userAgentreturns the "NT version" string in all 5 browsers. That means that userAgentis 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 navigatorhost 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

Also: http://www.quirksmode.org/js/detect.html

另外:http: //www.quirksmode.org/js/detect.html

回答by John Doe

window.navigator.appVersion.split("NT")[1].split(";")[0].trim()

Will return the Windows version.

将返回 Windows 版本。