jQuery - 检测操作系统和操作系统版本

发布于 2024-12-25 18:24:08 字数 982 浏览 4 评论 0原文

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

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

例如,对于 IE6,您必须使用 Trixie(我相信)来安装用户脚本,而这仅在 Win XP 上受支持。 Win XP 支持 IE7,Win XP 和 Windows 操作系统支持 IE8。 Win 7 和 IE9 仅在 Win 7 上受支持。适用于 IE7、8 和9 我建议使用 IEPro。特里克西和特里克西之间的区别IEPro 的问题是 Trixie 需要文件扩展名 .user.js,该文件必须保存在 C:/Program Files/bhelpuri 中。另一方面,IEPro 要求扩展名为 .ieuser 并保存到不同的位置。特别是对于 IE,我想检测版本并仅显示正确的链接(.user.js 或 .ieuser,具体取决于他们当前浏览器应使用的插件),以便将他们带到正确的版本该浏览器的文件的名称以及该操作系统/操作系统版本的正确保存路径。到目前为止这有意义吗?

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

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

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.

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?

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寻找我们的幸福 2025-01-01 18:24:08

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

OSVERSIONINFO

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

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/

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/

江南烟雨〆相思醉 2025-01-01 18:24:08

你可以使用这个很棒的 javascript 库: http://www.visitorjs.com/details 它最近是开源的

编辑:实际上,现在已重命名为 session.js http://github.com/codejoust/session.js 据我所知,这是你能得到的最好的。

You can use this great javascript library: http://www.visitorjs.com/details It is open-sourced recently

Edit: Actually, it is now renamed to session.js http://github.com/codejoust/session.js and to my knowledge, that is the best you can get.

御弟哥哥 2025-01-01 18:24:08

堆栈溢出问题
从浏览器检测确切的操作系统版本介绍了有关获取操作系统版本的一些有趣的细节来自 User-Agent 标头,我相信它包含可以从 JavaScript 访问的相同信息。

The Stack Overflow question
Detect exact OS version from browser goes into some interesting detail about getting the OS version from the User-Agent header which I believe contains the same information that can be accessed from JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文