Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - detecting the general platform Windows / Linux / Apple

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

like image 832
Martin Avatar asked Nov 17 '25 10:11

Martin


1 Answers

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

like image 113
Ionică Bizău Avatar answered Nov 19 '25 09:11

Ionică Bizău



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!