从 HTML/JS 进行简单的操作系统检查

发布于 2024-10-20 13:44:42 字数 177 浏览 5 评论 0 原文

我见过很多关于使用 JS 获取操作系统详细信息的问题。但我只是想知道我是否使用 Windows - 我的浏览器插件最初仅支持 Windows,所以我不想让用户毫无意义地下载 EXE/MSI 安装程序。

我认为你可以在不使用 JS 的情况下做一些这样的事情...我在旧书 IIRC 中看到了奇怪的条件 HTML 来检测 IE。

I've seen a number of questions about using JS to get detailed information about the OS. But I just want to know if I'm on Windows or not - my browser plugin will initially support Windows only so I don't want to make users pointlessly download a EXE/MSI installer.

I thought you could do some things like this without using JS... I've seen weird conditional HTML to detect IE in old books IIRC.

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

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

发布评论

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

评论(3

蓝戈者 2024-10-27 13:44:42

您可以为您的网站创建隐藏的下载链接和备用样式表,并使用条件注释在它们之间切换:

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->

在该样式表中,普通浏览器会看到以下内容:

#download
{
  display: none;
}

但是在特殊的 ie.css< 中/code> 样式表,你可以使其可见:

#download
{
  display: block !important;
}

如果你想用 JavaScript 来完成这一切,请尝试这个功能:

if (navigator.appVersion.indexOf('Win') != -1 && /MSIE (\d+\.\d+);/.test(navigator.userAgent))
{
  var version = new Number(RegExp.$1);

  if (version > 7)
  {
    alert('You are using a compatible browser.');
  }
}

我使用 Chrome 和 Linux,所以我无法测试它(而且我懒得切换用户代理字符串)。

You can create a hidden download link and an alternate stylesheet for your site and switch between them using conditional comments:

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->

And in that stylesheet, normal browsers see this:

#download
{
  display: none;
}

But within the special ie.css stylesheet, you can make it visible:

#download
{
  display: block !important;
}

If you want to do it all with JavaScript, try this function:

if (navigator.appVersion.indexOf('Win') != -1 && /MSIE (\d+\.\d+);/.test(navigator.userAgent))
{
  var version = new Number(RegExp.$1);

  if (version > 7)
  {
    alert('You are using a compatible browser.');
  }
}

I use Chrome and Linux, so I can't test it (and I'm too lazy to switch user agent strings).

执笏见 2024-10-27 13:44:42

不能用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

一人独醉 2024-10-27 13:44:42

如果你不使用 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.

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