Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从用户代理或Javascript检测64位或32位窗口?_Javascript_64 Bit_Operating System_User Agent - Fatal编程技术网

从用户代理或Javascript检测64位或32位窗口?

从用户代理或Javascript检测64位或32位窗口?,javascript,64-bit,operating-system,user-agent,Javascript,64 Bit,Operating System,User Agent,我想提供正确的下载版本。我的版本是: 32位窗口 64位窗口 Linux 使用用户代理字段检测Linux很容易;但是,是否有可能可靠地确定Windows是32位还是64位 用户可能使用奇怪的浏览器——IE和Firefox很常见,我们可能在某处有一个Opera用户;也可能是Chrome用户。我知道64位Windows7附带了32位和64位版本的IE,我想把我下载的64位版本都发给他们 (编辑为添加:我知道我应该提供所有选项,我会提供。但是。因此,我希望默认情况下提供正确的下载,以提高可用性。当

我想提供正确的下载版本。我的版本是:

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

用户可能使用奇怪的浏览器——IE和Firefox很常见,我们可能在某处有一个Opera用户;也可能是Chrome用户。我知道64位Windows7附带了32位和64位版本的IE,我想把我下载的64位版本都发给他们


(编辑为添加:我知道我应该提供所有选项,我会提供。但是。因此,我希望默认情况下提供正确的下载,以提高可用性。当然,如果我做对了,这是有帮助的,但如果我做错了,这是毫无帮助的。从目前的答案来看,似乎没有可靠的方法可以做到这一点).

并非100%确定,正如您所说,浏览器可能是32位版本,而操作系统可能是64位版本

要检测浏览器,请尝试以下代码:

<script language=javascript>   
  <!--   
  document.write("CPU :"+window.navigator.cpuClass);   
  //-->   
</script> 
var is32BitBrowser = true;
if( window.navigator.cpuClass != null && window.navigator.cpuClass.toLowerCase() == "x64" )
   is32BitBrowser = false;
if( window.navigator.platform.toLowerCase() == "win64" )
   is32BitBrowser = false;

CPU:ia64

对于IE


商业产品:

您可以查看
窗口.navigator.platform
窗口.navigator.cpuClass


我不确定你的情况,但我会考虑做其他大多数网站所做的事情,让用户选择他们下载的东西。他们可以下载到另一台机器上,安装在闪存设备上,或者只是想让32位版本在64位机器上运行。无论出于何种原因,我宁愿选择。

最可靠的解决方案是创建一个32位加载器应用程序,用于检测体系结构,然后下载并安装适当版本的应用程序

我已经检查了RC和Pino的另外两个答案。它们都不工作,因为与您建议的问题相同-64位Windows上的32位IE将错误地将平台标识为32位。由于大多数人在64位Windows上运行32位IE(许多插件如Flash在64位Windows中不可用),因此会有很多不准确的标识


Lee

适用于任何Internet Explorer浏览器的64位Windows上的64位IE

if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Win64") != -1 && navigator.userAgent.indexOf("x64") != -1){

   alert("This is 64 bit browser");

}
else {

   alert("Not 64 bit browser");

}
我使用了以下代码:

<script language=javascript>   
  <!--   
  document.write("CPU :"+window.navigator.cpuClass);   
  //-->   
</script> 
var is32BitBrowser = true;
if( window.navigator.cpuClass != null && window.navigator.cpuClass.toLowerCase() == "x64" )
   is32BitBrowser = false;
if( window.navigator.platform.toLowerCase() == "win64" )
   is32BitBrowser = false;

除了Mac电脑,它在任何地方都能工作。不幸的是,似乎不可能通过JavaScript获得这些信息:(.不过,还有一个窍门可以做。因为Adobe不支持x64浏览器上的flash player,所以您可以尝试检测它。如果检测成功,它肯定是32位浏览器,如果不成功,它肯定是没有flash插件的32位浏览器或64位浏览器。因为flash player的渗透率非常高(请参阅),这应该足够好,至少可以检测Mac下的x32浏览器。

我已经做了一些测试。以下是结果,希望能有所帮助:

64 bit MacOS + 64 bit Safari or 32 bit Chrome: window.navigator.platform=MacIntel 32 bit windows + safari: window.navigator.platform=Win32 64 bit Windows + 64 bit IE: window.navigator.platform=Win64 window.navigator.cpuClass=x64 64 bit Windows + 32 bit IE: window.navigator.platform=Win32 window.navigator.cpuClass=x86 64 bit Windows + 32 Firefox (or Chrome): window.navigator.platform=Win32 32 bit linux mint (i686) + firefox: window.navigator.platform=Linux i686 64 bit Ubuntu (x86_64) + 32 bit Chrome: window.navigator.platform=Linux i686 64 bit Ubuntu + 64 bit Epiphany: window.navigator.platform=Linux x86_64 尝试此操作,在用户代理字符串中查找WOW64(64位上的32位)或Win64(本机64位)

if(navigator.userAgent.indexOf(“WOW64”)!=-1|
navigator.userAgent.indexOf(“Win64”)!=-1){
警报(“这是一个64位操作系统”);
}否则{
警报(“不是64位操作系统”);
}
通过分析()我找到了以下字符串:

  • x86_64
  • x86-64
  • Win64
  • x64;(注意分号!如果没有分号,将出现误报。)
  • amd64
  • AMD64
  • WOW64
  • x64_64
此外,尽管它们具有不同的指令集且与Intel x86_64不兼容,但您可能需要检测以下情况:

  • ia64
  • 斯巴达64
  • ppc64
  • IRIX64
不过要注意,不要只查找包含“64”甚至“x64”的任何内容。Chrome的内部版本号、爬行器/机器人程序、库、.NET版本、分辨率等也可能包含字符串“x64”,而仍然是32位(或其他)操作系统

请注意,您可以不区分大小写地搜索所有这些字符串


我在ARM上找不到任何东西。可能是其他人?请编辑,这是一个社区wiki。

window.navigator.cpuClass和window.navigator.platform都返回浏览器平台,而不是系统平台。因此,如果您在64位系统上运行32位浏览器,则两个Varibale都将返回32位。这将是不正确的等。

对于带有64位IE的64位Windows,window.navigator.platform将为“Win64”,window.navigator.cpuClass将为“x64”

对于带有32位IE的64位Windows,
window.navigator.platform
将为“Win32”,而
window.navigator.cpuClass
将为“x86”

对于32位窗口,
window.navigator.platform
将是“Win32”,而
window.navigator.cpuClass
将是未定义的(我认为)

-


来源:我制作了..

我将上面的搜索结果恢复到这些JS函数中。希望它们能帮助这里的每个人快速响应他们的需求(以及我的需求!)

函数获取\u位\u系统\u架构()
{
var _to_check=[];
if(window.navigator.cpuClass)\u to_检查.push((window.navigator.cpuClass+).toLowerCase();
if(window.navigator.platform)_to_检查.push((window.navigator.platform+).toLowerCase();
if(navigator.userAgent)_to_check.push((navigator.userAgent+).toLowerCase());
var_64位_签名=[“x86_64”,“x86-64”,“Win64”,“x64;”,“amd64”,“amd64”,“WOW64”,“x64_64”,“ia64”,“sparc64”,“ppc64”,“IRIX64”];
变量_位=32,_i,_c;
外环:
对于(var_c=0;_c<_to_check.length;_c++)
{
对于(_i=0;_i<_64位\u签名.length;_i++)
{
if(_to_check[_c].indexOf(_64位签名[_i].toLowerCase())!=-1)
{
_位=64;
document.write( "Which is my current bits system architecture ? " + get_bits_system_architecture() + "<br>" );

document.write( "Is it 32 bits ? " + ( is_32bits_architecture() ? "YES" : "NO" ) + "<br>" );

document.write( "Is it 64 bits ? " + ( is_64bits_architecture() ? "YES" : "NO" ) );