Monday, April 23, 2012

Detect 64-bit or 32-bit Windows from User Agent or Javascript?


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


Source: Tips4all

7 comments:

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

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

    ReplyDelete
  3. 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

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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';
    };

    ReplyDelete
  6. 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");

    }

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

    ReplyDelete