How to know the user’s operating system version using Javascript?

Asked

Viewed 2,189 times

3

I wonder if there is how to do so when the person enters my HTML page, already identify which operating system it has, and then enable certain buttons.

For example if it has Windows 7, the program for windows 8 will be unable.

I don’t have any code yet, I’d just like to whether such an idea is possible?

2 answers

2

It is possible and there are a dozen solutions to this on the internet.

Look at two things:

It will be difficult for you to enable options for any and all OS as there are numerous.

New OS appear and the script will not be able to identify them, and a constant revision of the solution is required, whatever.

If possible, try to rely on other factors for your code decision.

  • Thank you, really. >o<

  • @Alis if my answer helped you, please accept it. =)

1

var OSNome = "";
if (window.navigator.userAgent.indexOf("Windows NT 10.0")!= -1) OSNome="Windows 10";
if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) OSNome="Windows 8";
if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) OSNome="Windows 7";
if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) OSNome="Windows Vista";
if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) OSNome="Windows XP";
if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) OSNome="Windows 2000";
if (window.navigator.userAgent.indexOf("Mac")            != -1) OSNome="Mac/iOS";
if (window.navigator.userAgent.indexOf("X11")            != -1) OSNome="UNIX";
if (window.navigator.userAgent.indexOf("Linux")          != -1) OSNome="Linux";
document.write('Seu Sistema Operacional: '+ OSNome);

Reference: https://stackoverflow.com/a/19176790/4312593

  • A much better solution exists than this: https://stackoverflow.com/a/18706818/3976193

  • Thank you.. Thank you >o<

  • And Windows 8.1?

  • 1

    Your code returns me "Windows 8" in Safari. In Chrome, FF, IE and Opera returns correct, "Windows 10".

  • In this code posted above, it is possible to check with some more implementations which would be the person’s windows, whether it is 32 or 64?

  • Yes, but like the comments above it is not the best approach. Following is the code: if (window.navigator.useragent.indexof("WOW64") != -1 || window.navigator.useragent.indexof("Win64") != -1 ){ Alert("Your operating site is 64 bit"); } Else { Alert("Your operating site is 32 bit"); }

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.