Detect operating system on the client machine using JavaScript

To detect the operating system on the client machine, you can use 
  • navigator.appVersion
  • navigator.userAgent property
The Navigator appVersion property is a read-only property and it returns
 a string that represents the version information of the browser. 

Example to display the operating system name using navigator.appVersion property:

				
					<!DOCTYPE html>
<html>
<head>
<title>OS Examples</title>
<script>
function findOS() {
var curOS="Not Named...";
if (navigator.appVersion.indexOf("Win")!=-1) curOS="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) curOS="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) curOS="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) curOS="Linux";
document.write('Your OS is: '+curOS);
}
</script>
</head>
<body data-ocssl='1' data-rsssl=1>
<h2>Find Your Operating System</h2>
<p>
<input type="button" value="Find Operating System" onclick="findOS()" />
</p>
</body>
</html>
				
			

Output:

Before Click on Button

After Click on Button

Example to display all the properties of the client system using navigator.appVersion property:

				
					<!DOCTYPE html>
<html>
<head>
<title>OS Examples</title>
<script>
function version() {
 var os = navigator.appVersion; 
document.write(os);
}
</script>
</head>
<body data-ocssl='1' data-rsssl=1>
<h2>Display the OS details</h2>
<p>
<input type="button" value="Find Operating System" onclick="version()" />
</p>

</body>

</html>
				
			

Output:

Before Click on Button

After Click on Button

Leave a Reply

Your email address will not be published. Required fields are marked *