How to find the operating system version using JavaScript?

0 votes
How can I find the OS name and OS version using JavaScript?
Oct 7 in Java-Script by kartik
• 36,020 points
48 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

var OSName = "Unknown";
if (window.navigator.userAgent.indexOf("Windows NT 10.0")!= -1) OSName="Windows 10";
if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) OSName="Windows 8";
if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) OSName="Windows 7";
if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) OSName="Windows Vista";
if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) OSName="Windows XP";
if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) OSName="Windows 2000";
if (window.navigator.userAgent.indexOf("Mac")            != -1) OSName="Mac/iOS";
if (window.navigator.userAgent.indexOf("X11")            != -1) OSName="UNIX";
if (window.navigator.userAgent.indexOf("Linux")          != -1) OSName="Linux";

Hope it helps!!

Thank you!!

answered Oct 7 by Niroj
• 78,480 points

Related Questions In Java-Script

0 votes
1 answer

How to get the file name from a full path using JavaScript?

Hello @kartik, Use this: var filename = fullPath.replace(/^.*[\\\/]/, '') This ...READ MORE

answered Sep 2 in Java-Script by Niroj
• 78,480 points
95 views
0 votes
1 answer

How to get the host url using javascript from the current page?

Hello @kartik, Use: var host = window.location.hostname; or possibly var host ...READ MORE

answered Oct 9 in Java-Script by Niroj
• 78,480 points
69 views
0 votes
1 answer

How to get the browser to navigate to URL in JavaScript?

Hii, This works in all browsers: window.location.href = '...'; If ...READ MORE

answered May 28 in Java-Script by Niroj
• 78,480 points
239 views
0 votes
1 answer

How to list the properties of a JavaScript object?

Hii @kartik, Use Reflect.ownKeys(): var obj = {a: 1, b: ...READ MORE

answered Jun 8 in Java-Script by Niroj
• 78,480 points
114 views
0 votes
1 answer

How to access PHP var from external javascript file?

Hello @kartik, You don't really access it, you ...READ MORE

answered Jul 6 in Java-Script by Niroj
• 78,480 points
870 views
0 votes
1 answer

How do I escape a single quote in SQL Server?

Hello @kartik, Single quotes are escaped by doubling ...READ MORE

answered Jul 21 in PHP by Niroj
• 78,480 points
982 views
0 votes
1 answer

How to specify a port to run a create-react-app based project?

Hello @kartik, You could use cross-env to set the port, ...READ MORE

answered Jul 22 in Angular by Niroj
• 78,480 points
940 views
0 votes
1 answer

How do you set a default value for a MySQL Datetime column?

Hello @kartik, In version 5.6.5, it is possible ...READ MORE

answered Aug 18 in PHP by Niroj
• 78,480 points
437 views
0 votes
1 answer

How to Scroll to the top of the page using JavaScript?

Hii @kartik, Using javascript <script> $("a[href='#top']").click(function() { ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 78,480 points
84 views
0 votes
1 answer

How to find event listeners on a DOM node when debugging or from the JavaScript code?

Hii @kartik, It is possible to list all ...READ MORE

answered Jun 8 in Java-Script by Niroj
• 78,480 points
2,328 views