【问题标题】:jQuery - detecting the general platform Windows / Linux / ApplejQuery - 检测通用平台 Windows/Linux/Apple
【发布时间】:2013-06-05 06:13:47
【问题描述】:

这是基于jQuery - detecting the operating system and operating system version

我只想测试平台 Windows 或 Linux 或 Apple。对吗?

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)
    };
}());

测试:http://jsfiddle.net/k5mGC/4/

是否有完整的用户代理结果列表?我只找到了像http://user-agents.my-addr.com/user_agent_request/user_agent_examples-and-user_agent_types.php这样的示例列表

【问题讨论】:

    标签: jquery operating-system detect


    【解决方案1】:

    您也可以使用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

    【讨论】:

    • 谢谢。但这也使用了 userAgent 信息,所以 Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/0.8.12 不适用于 indexOf("Linux")
    • 你说“也使用 userAgent 信息”是什么意思?
    • 我提到你的版本并不比我的安全。
    猜你喜欢
    • 2011-06-09
    • 2010-11-17
    • 1970-01-01
    • 2014-11-16
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多