How to Determine the Operating System of the Client Machine with JavaScript

To determine the operating system of the client machine on which a browser is executing JavaScript, use the appVersion property of the JavaScript navigator object, as demonstrated in the following example:

document.write(navigator.appVersion);

The information given in this property can be extrapolated, albeit in a somewhat rudimentary way, to determine whether the operating system is Windows or Macintosh, as shown below:

var strOS = navigator.appVersion;

if (strOS.toLowerCase().indexOf('win') != -1)
document.write('Windows');
else if (strOS.toLowerCase().indexOf('mac') != -1)
document.write('Macintosh');

Related articles:
JavaScript String Object indexOf Method

Leave a Reply