使用jQuery检测iPad用户? [英] Detect iPad users using jQuery?
问题描述
有没有办法检测当前用户是否使用jQuery / JavaScript使用iPad?
Is there a way to detect if the current user is using an iPad using jQuery/JavaScript?
推荐答案
iPad检测
您应该可以通过查看 userAgent
property:
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 Detection
同样, 平台用于检查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)
}
备注
虽然它有效,但您通常应避免执行特定于浏览器的检测,因为它通常不可靠(并且可以欺骗)。最好使用实际的 feature-detection 在大多数情况下,可以通过像 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 HowTo:检测iPad用户使用JavaScript
- jQuery HowTo:Detecting&重定向iPad / iPhone用户
- David Walsh的博客:检测iPad使用情况
- 通过PHP检测iPad使用情况
- jQuery HowTo: Detect iPad users using JavaScript
- jQuery HowTo: Detecting & Redirecting iPad / iPhone Users
- David Walsh's Blog : Detecting iPad use
- Detecting iPad use via PHP
这篇关于使用jQuery检测iPad用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!