Detecting user's Windows operating system version using the user-agent.

Monday, August 5, 2013

to get the user-agent information of the user's browser:

navigator.userAgent

String to look for:
WinXP:       NT 5.1
Vista :         NT 6.0
Windows 7: NT 6.1
Windows 8: NT 6.2

Tiny JavaScript function to get user's OS:
function getOSVersion() {
    navigator.userAgent.indexOf("NT 5.") != -1 return "XP";
    /* all Service packs included */
    navigator.userAgent.indexOf("NT 6.0") != -1 return "Vista";
    navigator.userAgent.indexOf("NT 6.1") != -1 return "7";
    navigator.userAgent.indexOf("NT 6.2") != -1 return "8";
    return "Other";
}
 

About Me

My photo
Front-end Developer with over 9 years of experience in developing Web 2.0 sites with a keen eye for UX. Avid technology enthusiast; gadget freak; old school PC gamer; loves developing Apps & Data Visualizations.

My Website

Stack Overflow profile

Twitter Profile

Facebook profile