使用jQuery检测iPad用户?

有没有一种方法可以通过jQuery / JavaScript检测当前用户是否正在使用iPad?



汪汪一只猫
浏览 405回答 3
3回答

阿晨1998

iPad检测通过查看userAgent属性,您应该能够检测到iPad用户:var is_iPad = navigator.userAgent.match(/iPad/i) != null;iPhone / iPod检测同样,platform用于检查iPhone或iPods等设备的属性:function is_iPhone_or_iPod(){     return navigator.platform.match(/i(Phone|Pod))/i)}笔记当它起作用时,通常应该避免执行特定于浏览器的检测,因为它通常不可靠(并且可能被欺骗)。在大多数情况下,最好使用实际的特征检测,这可以通过Modernizr之类的库来完成。正如Brennen的回答所指出的那样,在Facebook应用程序中执行此检测时可能会出现问题。请参阅他的答案以处理这种情况。

慕运维8079593

我用这个:function fnIsAppleMobile() {    if (navigator && navigator.userAgent && navigator.userAgent != null)     {        var strUserAgent = navigator.userAgent.toLowerCase();        var arrMatches = strUserAgent.match(/(iphone|ipod|ipad)/);        if (arrMatches != null)              return true;    } // End if (navigator && navigator.userAgent)     return false;} // End Function fnIsAppleMobilevar bIsAppleMobile = fnIsAppleMobile(); // TODO: Write complaint to CrApple asking them why they don't update SquirrelFish with bugfixes, then remove
打开App,查看更多内容
随时随地看视频慕课网APP