在javascript中检测XP或windows-7

问题描述:

如何检测我的Web应用程序是否在使用JavaScript的Window XP或Windows 7上运行?在javascript中检测XP或windows-7

任何帮助/示例代码将不胜感激。

+7

请问*为什么*? –

+1

[jQuery - 检测操作系统和操作系统版本]的可能重复(http://stackoverflow.com/questions/8774560/jquery-detecting-the-operating-system-and-operating-system-version) – Quentin

+0

使用'导航器变量属性。如'navigator.appVersion','navigator.userAgent','navigator.platform'。例如_“Windows NT 6.1; WOW64;”_是指Win7 x64(以WOW模式运行的浏览器)。 –

关于浏览器和操作系统的信息包含在navigator对象中。

刚刚尝试在这两个操作系统(WIN7和WINXP)一

window.alert(navigator.appVersion); 

,并期待在不同者均基于字符串的警报弹出。 稍微解析一下这样的字符串,你将能够检索到你需要的所有信息。

Understanding User Agent Strings

输出你的浏览器的用户代理,使用:

javascript:alert(navigator.userAgent) 

这会给你的东西等的输出:

"Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.1)" 

如果您解析userAgent数据对于平台令牌(在上例中为Windows NT 6.1),您将会ret瓮的Windows版本。请考虑到每个浏览器都使用userAgent自己的格式,并且检测功能可能是更好的方法。