jQuery - detecting the operating system and operating system version

34,559

Solution 1

Your best bet is to use the navigator.userAgent property. It will give the windows version number. You can see a table of how the Windows version number map to the OS here:

OSVERSIONINFO

Here is some example detection code:

var os = (function() {
    var ua = navigator.userAgent.toLowerCase();
    return {
        isWin2K: /windows nt 5.0/.test(ua),
        isXP: /windows nt 5.1/.test(ua),
        isVista: /windows nt 6.0/.test(ua),
        isWin7: /windows nt 6.1/.test(ua),
        isWin8: /windows nt 6.2/.test(ua),
        isWin81: /windows nt 6.3/.test(ua)
    };
}());

if(os.isWin7) {
    ...
}

http://jsfiddle.net/45jEc/

Solution 2

You can use this great javascript library: http://www.visitorjs.com/details It is open-sourced recently

Edit: Actually, it is now renamed to session.js http://github.com/codejoust/session.js and to my knowledge, that is the best you can get.

Solution 3

The Stack Overflow question Detect exact OS version from browser goes into some interesting detail about getting the OS version from the User-Agent header which I believe contains the same information that can be accessed from JavaScript.

Share:
34,559
ClarkeyBoy
Author by

ClarkeyBoy

I am currently developing a website in VB.Net with CSS/SASS, JQuery and JQuery UI for Heritage Art Papers Ltd which achieved 66% as my final year project at university.. It was the dissertation which let me down.. The website has a full administration frontend for editing what end users see on the customer frontend. My aim over the period I am working on it is for administrators to eventually be able to add and remove attributes for specific types of item (that is: Range, Collection, Design, RangeCollection, CollectionDesign and RangeCollectionDesign [the final product with a product code]). They will then be able to reference these in the item template for the catalogue by using square brackets. Over time the system should become very sophisticated, and should log all actions (big or small) and highlight the important ones to admin - for example hacking attempts. I know CSS/SASS, HTML (obviously), ASP, ASP.Net (VB), PHP (a bit), Java (a bit) and JQuery/JQuery UI. I would like to learn C++ or C#, but to be honest I just dont have the time at the moment. I have just started work for StepStone Solutions in Luton, as an Application Developer. Loving the job so far, having just finished my 2nd week.

Updated on July 22, 2022

Comments

  • ClarkeyBoy
    ClarkeyBoy almost 2 years

    I have been writing a userscript for the past few months, for my company, and have just designed the main site for it with installation instructions (our employees are based all around the world and very few have heard of userscripts, let alone used them, so this frontend is meant to cut down the time I spend supporting the script).

    What I would like to do is, on the installation page, detect which browser and OS / OS version they're using so that I can highlight the most relevant instructions slightly darker than the rest, or simply not display irrelevant sections.

    For example for IE6 you must use Trixie (I believe) to install userscripts, and this is supported on Win XP only. IE7 is supported on Win XP, IE8 is supported on Win XP & Win 7 and IE9 is supported on Win 7 only. For IE7, 8 & 9 I am advising to use IEPro. The difference between Trixie & IEPro is that Trixie requires a file extension of .user.js which must be saved in C:/Program Files/bhelpuri. IEPro, on the other hand, requires the extension to be .ieuser and saves to a different location. For IE specifically, I would like to detect the version and display only the correct link (either .user.js or .ieuser, depending on what plugin they should be using for their current browser) so that they're taken to the correct version of the file for that browser with the correct save path for that OS / OS version. Is this making any sense so far?

    Basically my question is, does anyone know of a way to detect the operating system version? I am currently using http://www.stoimen.com/blog/2009/07/04/jquery-os-detection/ but that doesn't give the OS version, only the OS. I have tried looping through all of the variables stored in the navigator object with no success. Any help would be greatly appreciated.

    Edit: Thanks to Nates answer, I have put the exact code at http://jsfiddle.net/Mu8r5/1/. I hope this helps someone in the future.