Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery/Javascript to detect OS without a plugin?

I am looking for a way to detect the OS for a downloads page using jQuery or Javascript to recommend specific files for Mac vs Windows. I was hoping to do it without adding another plugin to my page.

like image 909
Tim Withers Avatar asked Aug 12 '11 18:08

Tim Withers


People also ask

How to detect OS in JQuery?

Try: var os = navigator. platform; Then handle the os variable accordingly for your result.

How can you detect the client operating system using Javascript?

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


1 Answers

Try:

var os = navigator.platform;

Then handle the os variable accordingly for your result.

You can also loop through each object of the navigator object to help get you more familiarized with the objects:

<script type="text/javascript"> for(var i in navigator){     console.log(i+"="+navigator[i]+'<br>'); } </script> 
like image 57
Robert Avatar answered Sep 27 '22 23:09

Robert