Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  52] [ 6]  / answers: 1 / hits: 156769  / 14 Years ago, thu, january 6, 2011, 12:00:00

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


More From » jquery

 Answers
134

iPad Detection



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



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


Notes



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.



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.



Related Resources




[#94350] Tuesday, January 4, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrances

Total Points: 184
Total Questions: 100
Total Answers: 92

Location: Tokelau
Member since Sun, May 7, 2023
1 Year ago
;