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

2

I would like to know if there is a way to make it so that when the person enters my HTML page, already identifies which operating system it has, and then enables certain buttons.

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

I do not have any code done yet, just like to know if such an idea is possible?

    
asked by anonymous 01.09.2017 / 21:15

2 answers

2

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

Pay attention to two things:

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

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

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

    
01.09.2017 / 21:21
0

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: link

    
01.09.2017 / 21:20