从用户代理或 Javascript 检测 64 位或 32 位 Windows? [英] Detect 64-bit or 32-bit Windows from User Agent or Javascript?

查看:24
本文介绍了从用户代理或 Javascript 检测 64 位或 32 位 Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供正确版本的下载.我拥有的版本是:

I want to offer the right version of a download. The versions I have are:

  • 32 位 Windows
  • 64 位 Windows
  • Linux

使用用户代理字段检测 Linux 很容易;但是否有可能可靠地确定 Windows 是 32 位还是 64 位?

Detecting Linux using the User Agent field is easy; but is it possible to reliably figure out if Windows is 32-bit or 64-bit?

用户可能使用奇怪的浏览器——IE 和 Firefox 很常见,我们可能在某个地方有一个 Opera 用户;也许也是 Chrome 用户.我知道 64 位 Windows 7 附带 32 位和 64 位版本的 IE,我想将我下载的 64 位版本发送给他们.

Users might be using weird browsers - IE and Firefox are common, and we probably have an Opera user somewhere; maybe a Chrome user too. I know that 64-bit Windows 7 ships with 32-bit and 64-bit versions of IE, and I'd like to send them both the 64-bit version of my download.

(编辑添加:我知道我应该提供所有选项,我会.但是 人们不阅读选项.所以我想默认提供正确的下载,以提高可用性.当然,虽然这在我做对时很有帮助,但如果我做错了就非常无用. 从目前的答案来看,似乎没有可靠的方法可以做到这一点).

(Edited to add: I know that I should provide all the options, and I will. But people don't read the options. So I wanted to provide the right download by default, to improve usability. Of course, while this is helpful if I get it right, it's extremely unhelpful if I get it wrong. And from the answers so far, it doesn't look like there's a reliable way of doing this).

推荐答案

试试这个,在用户代理字符串中查找 WOW64(64 位上的 32 位)或 Win64(本机 64 位).

Try this, looks for WOW64 (32-bit on 64-bit) or Win64 (native 64-bit) in the user-agent string.

    if (navigator.userAgent.indexOf("WOW64") != -1 || 
        navigator.userAgent.indexOf("Win64") != -1 ){
       alert("This is a 64 bit OS");
    } else {
       alert("Not a 64 bit OS");
    }

这篇关于从用户代理或 Javascript 检测 64 位或 32 位 Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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