jQuery - 检测操作系统和操作系统版本 [英] jQuery - detecting the operating system and operating system version

查看:873
本文介绍了jQuery - 检测操作系统和操作系统版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去几个月一直在为我的公司编写用户脚本,并且刚刚为其设计了主要网站的安装说明(我们的员工遍布全球,很少有人听说过用户脚本,更不用说了使用它们,所以这个前端意味着减少我花在支持脚本上的时间。)

I have been writing a userscript for the past few months, for my company, and have just designed the main site for it with installation instructions (our employees are based all around the world and very few have heard of userscripts, let alone used them, so this frontend is meant to cut down the time I spend supporting the script).

我想要做的是,在安装页面上,检测哪个他们正在使用的浏览器和操作系统/操作系统版本,以便我可以突出显示比其余部分稍暗的最相关指令,或者只是不显示不相关的部分。

What I would like to do is, on the installation page, detect which browser and OS / OS version they're using so that I can highlight the most relevant instructions slightly darker than the rest, or simply not display irrelevant sections.

例如IE6你必须使用Trixie(我相信)来安装用户脚本,这仅在Win XP上受支持。 Win XP支持IE7,Win XP和Linux支持IE8。 Win 7仅支持Win 7和IE9。对于IE7,8& 9我建议使用IEPro。 Trixie& IEPro是Trixie需要.user.js的文件扩展名,必须保存在C:/ Program Files / bhelpuri中。另一方面,IEPro要求扩展名为.ieuser并保存到其他位置。对于IE专门,我想检测版本并只显示正确的链接(.user.js或.ieuser,取决于他们应该为他们当前的浏览器使用什么插件),以便它们被带到正确的版本该浏览器的文件,具有该OS / OS版本的正确保存路径。到目前为止这是否有意义?

For example for IE6 you must use Trixie (I believe) to install userscripts, and this is supported on Win XP only. IE7 is supported on Win XP, IE8 is supported on Win XP & Win 7 and IE9 is supported on Win 7 only. For IE7, 8 & 9 I am advising to use IEPro. The difference between Trixie & IEPro is that Trixie requires a file extension of .user.js which must be saved in C:/Program Files/bhelpuri. IEPro, on the other hand, requires the extension to be .ieuser and saves to a different location. For IE specifically, I would like to detect the version and display only the correct link (either .user.js or .ieuser, depending on what plugin they should be using for their current browser) so that they're taken to the correct version of the file for that browser with the correct save path for that OS / OS version. Is this making any sense so far?

基本上我的问题是,是否有人知道检测操作系统版本的方法?我目前正在使用 http://www.stoimen.com/博客/ 2009/07/04 / jquery-os-detection / 但这并没有提供操作系统版本,只提供操作系统。我已经尝试循环遍历导航器对象中存储的所有变量但没有成功。任何帮助将不胜感激。

Basically my question is, does anyone know of a way to detect the operating system version? I am currently using http://www.stoimen.com/blog/2009/07/04/jquery-os-detection/ but that doesn't give the OS version, only the OS. I have tried looping through all of the variables stored in the navigator object with no success. Any help would be greatly appreciated.

编辑:感谢Nates的回答,我把确切的代码放在 http://jsfiddle.net/Mu8r5/1/ 。我希望这可以帮助将来的某个人。

Thanks to Nates answer, I have put the exact code at http://jsfiddle.net/Mu8r5/1/. I hope this helps someone in the future.

推荐答案

最好的办法是使用navigator.userAgent属性。它将给出Windows版本号。您可以在此处查看Windows版本号如何映射到操作系统的表格:

Your best bet is to use the navigator.userAgent property. It will give the windows version number. You can see a table of how the Windows version number map to the OS here:

OSVERSIONINFO

以下是一些示例检测代码:

Here is some example detection code:

var os = (function() {
    var ua = navigator.userAgent.toLowerCase();
    return {
        isWin2K: /windows nt 5.0/.test(ua),
        isXP: /windows nt 5.1/.test(ua),
        isVista: /windows nt 6.0/.test(ua),
        isWin7: /windows nt 6.1/.test(ua),
        isWin8: /windows nt 6.2/.test(ua),
        isWin81: /windows nt 6.3/.test(ua)
    };
}());

if(os.isWin7) {
    ...
}

http://jsfiddle.net/45jEc/

这篇关于jQuery - 检测操作系统和操作系统版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆