This based on jQuery - detecting the operating system and operating system version
I just want to test the platform Windows or Linux or Apple. Would that be correct?
var os = (function () {
var ua = navigator.userAgent.toLowerCase();
return {
isWindows: /(windows|win95|win32|win64)/.test(ua),
isLinux: /(linux|freebsd|ssl-mm)/.test(ua),
isApple: /(mac os|mac_powerpc)/.test(ua)
};
}());
Test: http://jsfiddle.net/k5mGC/4/
Is there a full list of user agent results? I only found example lists like http://user-agents.my-addr.com/user_agent_request/user_agent_examples-and-user_agent_types.php
You can also use navigator.appVersion.
var OSName = "Unknown OS";
if (navigator.appVersion.indexOf("Win") != -1) OSName = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
if (navigator.appVersion.indexOf("X11") != -1) OSName = "UNIX";
if (navigator.appVersion.indexOf("Linux") != -1) OSName = "Linux";
alert("You are using " + OSName);
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With