从 HTML/JS 进行简单的操作系统检查
我见过很多关于使用 JS 获取操作系统详细信息的问题。但我只是想知道我是否使用 Windows - 我的浏览器插件最初仅支持 Windows,所以我不想让用户毫无意义地下载 EXE/MSI 安装程序。
我认为你可以在不使用 JS 的情况下做一些这样的事情...我在旧书 IIRC 中看到了奇怪的条件 HTML 来检测 IE。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为您的网站创建隐藏的下载链接和备用样式表,并使用条件注释在它们之间切换:
在该样式表中,普通浏览器会看到以下内容:
但是在特殊的
ie.css< 中/code> 样式表,你可以使其可见:
如果你想用 JavaScript 来完成这一切,请尝试这个功能:
我使用 Chrome 和 Linux,所以我无法测试它(而且我懒得切换用户代理字符串)。
You can create a hidden download link and an alternate stylesheet for your site and switch between them using conditional comments:
And in that stylesheet, normal browsers see this:
But within the special
ie.css
stylesheet, you can make it visible:If you want to do it all with JavaScript, try this function:
I use Chrome and Linux, so I can't test it (and I'm too lazy to switch user agent strings).
不能用navigator.platform查看吗?
就像 if (navigator.platform == 不管怎样) 是这样的。
是的:
http://www.w3schools.com/jsref/prop_nav_platform.asp
Can't you use the navigator.platform to check?
so like if (navigator.platform == whatever) it's so and so.
yup:
http://www.w3schools.com/jsref/prop_nav_platform.asp
如果你不使用 javascript,我唯一能想到的就是利用 IE 条件注释< /a>,但即便如此,也只允许您包含/排除一些 javascript 或 css。
如果您确实想了解操作系统、浏览器等,您可以尝试解析用户代理字符串。它报告浏览器、操作系统和其他值,但它并不可靠(例如,您可以伪造字符串)。 Quirksmode 具有很好的检测浏览器和操作系统的功能。
If you're not using javascript, the only thing I can think of is taking advantage of IE Conditional comments, but even then, that will only allow you to include/exclude some javascript or css.
If you really want to know the OS, browser, etc. you could try parsing the user-agent string. It reports on the browser, operating system, and other values, but it isn't reliable (for example, you can forge the string). Quirksmode has a good function to detect the browser and OS.