使用 jQuery 检测 iPad 用户? [英] Detect iPad users using jQuery?

查看:20
本文介绍了使用 jQuery 检测 iPad 用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 jQuery/JavaScript 检测当前用户是否在使用 iPad?

Is there a way to detect if the current user is using an iPad using jQuery/JavaScript?

推荐答案

iPad 检测

您应该能够通过查看 userAgent 属性:

You should be able to detect an iPad user by taking a look at the userAgent property:

var is_iPad = navigator.userAgent.match(/iPad/i) != null;

iPhone/iPod 检测

类似地,平台 检查 iPhone 或 iPod 等设备的属性:

Similarly, the platform property to check for devices like iPhones or iPods:

function is_iPhone_or_iPod(){
     return navigator.platform.match(/i(Phone|Pod))/i)
}

注意事项

虽然它有效,但您通常应该避免执行特定于浏览器的检测,因为它通常不可靠(并且可能被欺骗).最好使用实际的 /a> 在大多数情况下,可以通过像 Modernizr 这样的库来完成.

While it works, you should generally avoid performing browser-specific detection as it can often be unreliable (and can be spoofed). It's preferred to use actual feature-detection in most cases, which can be done through a library like Modernizr.

正如Brennen 的回答中指出的那样,在 Facebook 应用中执行此检测时可能会出现问题.请参阅他对处理这种情况的回答.

As pointed out in Brennen's answer, issues can arise when performing this detection within the Facebook app. Please see his answer for handling this scenario.

相关资源

这篇关于使用 jQuery 检测 iPad 用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆