89

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

  • 32-bit Windows
  • 64-bit Windows
  • Linux

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?

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).

2
  • 1
    Surprising that your Linux version works on x86, x64 and ARM.
    – MSalters
    Nov 18, 2009 at 12:16
  • 9
    The "Linux version" is source code. The Windows versions are binary.
    – user9876
    Nov 19, 2009 at 17:08

12 Answers 12

58

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");
    }

3
  • 5
    This works well, except for Safari on 64-bit Windows 7, which lacks WOW64, lacks Win64, and reports its window.navigator.platform as win32. I've tried it in Safari 4/Win; later versions may change. Dec 8, 2011 at 22:19
  • 2
    Not 100% accurate but it is a good clue, since there is no better way of detecting it reliably.
    – Vitim.us
    Mar 25, 2013 at 5:40
  • 1
    I think it would be better to assume the user has x64 at this point in time. Using an opt-in detection algorithm to detect an architecture that over 99.5% of consumers have should by now yield more false positives than just assuming they all have it.
    – Zyl
    Feb 17, 2021 at 17:26
42

I've done some tests. Here are the results, hope it helps:

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

So far i've used this code:

deployJava.isWin64OS = function() {
    return navigator.userAgent.indexOf('WOW64')>-1 || window.navigator.platform=='Win64';
};
1
  • 2
    That's not accurate. Windows 64-bit w/ Chrome 64-bit yields "Win32" as well.
    – Apollo
    Mar 31, 2017 at 13:52
35

Analysing around 14000 unique user-agents (from here), I've come up with the following strings to look for:

  • x86_64
  • x86-64
  • Win64
  • x64; (Mind the semicolon! Without it you will have false-positives.)
  • amd64
  • AMD64
  • WOW64
  • x64_64

Additionally, although they have different instruction sets and are not compatible with Intel x86_64, you may want to detect the following:

  • ia64
  • sparc64
  • ppc64
  • IRIX64

Beware though, don't just look for anything containing "64" or even "x64". Chrome's build numbers, spiders/bots, libraries, .NET versions, resolutions, etc. may also contain the string "x64" while still being a 32-bits (or other) OS.

Note that you can search for all those strings case-insensitively.

I have not been able to find anything on ARM. Perhaps someone else? Please edit, it is a community wiki.

1
24

You can check the window.navigator.platform and the window.navigator.cpuClass.

I'm not sure your situation, but I would consider just doing what most other sites do and let the user choose which download they get. They could be downloading it for another machine, to put on a flash device, or just may simply want the 32-bit version to run on their 64-bit box. Whatever reason, I would rather have the choice.

3
  • 6
    Where I work, we've had all the download options available for a long time, but users often make the mistake of downloading the wrong version for their system.
    – exupero
    May 11, 2011 at 14:13
  • 1
    Most users just pick the first one when they are unsure. When you want to give a recommendation to the user, you could place this version first and maybe even make it a bit larger than the others.
    – Philipp
    Sep 29, 2012 at 10:37
  • 4
    Firefox on Windows 7, 64-bit: navigator.cpuClass === undefined, navigator.platform === "Win32". IE9 on same machine, navigator.cpuClsas === "x86". Neither of these is any use whatsoever for detecting 64-bit Windows. navigator.userAgent does contain WOW64, though, so that answer is valid. May 7, 2013 at 1:47
19

The most reliable solution would be to create a 32bit loader application that detects the architecture and then downloads and installs the appropriate version of your application.

I've checked the other two answers from RC and Pino. They both do not work because of the same problem as you suggest - 32-bit IE on 64-bit Windows will wrongly identify the platform as 32-bit. As most people run 32-bit IE on 64-bit Windows (many plugins e.g. Flash are not available in 64-bit), there will be a lot of innacurate identifications

Lee

4
  • 1
    I'm guessing someone (not me) voted it down because it doesn't directly answer the question. However, it is an alternative way of accomplishing what I want to do.
    – user9876
    Nov 19, 2009 at 17:12
  • 3
    32 bit IE includes the WOW64 token, so it would be easy to pick out. Dec 12, 2009 at 10:05
  • Best and most user friendly solution in my opinion.
    – Radu
    Jun 30, 2011 at 13:44
  • I definitely hate these installers, but it is a option, please just don't annoy your users forcing then to also install your beutiful toolbar.
    – Vitim.us
    Mar 25, 2013 at 5:46
9

Not with 100% certainty as you say the browser could be a 32bit version while the OS a 64bit.

To detect the browser, please try the following code:

<script language=javascript>   
  <!--   
  document.write("CPU :"+window.navigator.cpuClass);   
  //-->   
</script> 

CPU : ia64

For IE.

http://msdn.microsoft.com/en-us/library/ms531090%28VS.85%29.aspx

Commercial Product : https://www.cyscape.com/showbrow.aspx

1
  • 5
    This does not address original question. This produces "x86" on a 64 bit Windows 7 box using 32-bit IE. Question was asking to detect system bitness and os, not browser bitness.
    – Pete
    Oct 8, 2010 at 21:42
5

For 64-bit Windows with 64-bit IE window.navigator.platform will be "Win64" and window.navigator.cpuClass will be "x64".

For 64-bit Windows with 32-bit IE, window.navigator.platform will be "Win32" and window.navigator.cpuClass will be "x86".

For 32-bit Windows, window.navigator.platform will be "Win32" and window.navigator.cpuClass will be undefined (I think).

-

Source: I made an app that uses JavaScript to determine if someone is using a 32 bit or 64 bit processor. You can see the code here on GitHub.

1
  • 1
    You are incorrect about your last point, that does not mean that the user has a 32-but windows machine. In fact all of the above just gives you the browser info, not OS.
    – Mo Beigi
    Apr 24, 2015 at 7:13
3

I resumed the results of the nice search above into these JS functions. Hope they can help everybody here to catch up a quick response to their needs (and, as well, to mine too !)

function get_bits_system_architecture()
{
    var _to_check = [] ;
    if ( window.navigator.cpuClass ) _to_check.push( ( window.navigator.cpuClass + "" ).toLowerCase() ) ;
    if ( window.navigator.platform ) _to_check.push( ( window.navigator.platform + "" ).toLowerCase() ) ;
    if ( navigator.userAgent ) _to_check.push( ( navigator.userAgent + "" ).toLowerCase() ) ;

    var _64bits_signatures = [ "x86_64", "x86-64", "Win64", "x64;", "amd64", "AMD64", "WOW64", "x64_64", "ia64", "sparc64", "ppc64", "IRIX64" ] ;
    var _bits = 32, _i, _c ;
    outer_loop:
    for( var _c = 0 ; _c < _to_check.length ; _c++ )
    {
        for( _i = 0 ; _i < _64bits_signatures.length ; _i++ )
        {
            if ( _to_check[_c].indexOf( _64bits_signatures[_i].toLowerCase() ) != -1 )
            {
               _bits = 64 ;
               break outer_loop;
            }
        }
    }
    return _bits ; 
}


function is_32bits_architecture() { return get_bits_system_architecture() == 32 ? 1 : 0 ; }
function is_64bits_architecture() { return get_bits_system_architecture() == 64 ? 1 : 0 ; }

Test it:

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" ) );

Thanks to everyone!

0
2

I used following code:

var is32BitBrowser = true;
if( window.navigator.cpuClass != null && window.navigator.cpuClass.toLowerCase() == "x64" )
   is32BitBrowser = false;
if( window.navigator.platform.toLowerCase() == "win64" )
   is32BitBrowser = false;

It worked everywhere expect Mac computers. And unfortunately seems that it's not possible to get that information via JavaScript :(. However one more trick could be done there. Because Adobe didn't support flash player on x64 browsers, you can just try to detect it. If detection is successful, than it is definitely 32 bit browser, if no, than it's 32 bit browser without flash plugin or it's 64 bit browser. Because penetration rate of Flash player is quite huge(see http://www.adobe.com/products/player_census/flashplayer/version_penetration.html), this should be good enough to at least detect x32 browser under Mac.

1

64-bit IE on 64-bit Windows for any Internet Explorer browser

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");

}
1

Both window.navigator.cpuClass and window.navigator.platform return the browser platform. Not the system platform. So if you are running a 32-bit browser on a 64-bit system then both varibales would return 32-bit. Which would be incorrect.

1

I've found this old question and thought updating with a recent open source library I found: https://github.com/faisalman/ua-parser-js

According to the docs, the method getCPU() returns { architecture: '' }, with the following possible values: 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc, ppc, sparc, sparc64.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.