【问题标题】:How can I tell the difference between an iPhone, iPad and iPod in Javascript?如何在 JavaScript 中区分 iPhone、iPad 和 iPod?
【发布时间】:2012-10-16 18:30:58
【问题描述】:

我可以检查用户是否在使用移动设备,并且我可以检查用户是否在使用移动 safari。但是我如何才能检查用户正在使用哪种特定类型的移动 iDevice?

【问题讨论】:

    标签: javascript iphone ipad user-agent ipod


    【解决方案1】:
    var matchiDevice = new RegExp("i[p|P](hone|ad|od)");
    var iDeviceTest = matchiDevice.exec(navigator.userAgent);
    
    if (iDeviceTest != null) {
        var iDevice = iDeviceTest[0];
        alert("You are using a " + iDevice + "!");
    }
    else 
    {
        alert("You are not using an iDevice!");
    }
    

    这将告诉您它是否是 iDevice,以及是哪一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 2015-12-25
      相关资源
      最近更新 更多