Using Javascript to Detect OS

March 24, 2016 — Leave a comment

Detect OSX or Windows with Javascript

We can easily detect whether client’s machine is PC or Mac with Javascript.
We can just analyze the value of navigator.appVersion or navigator.userAgent. Be careful, some clients will spoof the userAgent.

// Javascript code for OSX or Windows detection
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

document.write('Your OS: '+OSName);

Mike

Posts Twitter Facebook

My name is Michael Le, and I am a web developer.

No Comments

Be the first to start the conversation.

Leave a Reply