Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad version detection in JavaScript

Is it possible to check for the iPad version (1 or 2) in a web application? As the user agent looks identical (see http://www.webtrends.com/Support/KnowledgeBase/SolutionDetail.aspx?Id=50140000000acbiAAA) a standard check by browser does not work here.

Can we check for features (like the gyroscope) in JavaScript which are only available in version 2?

like image 215
fbrandel Avatar asked Sep 13 '11 10:09

fbrandel


People also ask

How do I identify JavaScript on iPad?

To detect iPad Pro as iPad with JavaScript, we can check various properties of navigator . to define the isIOS and isIpadOS functions to check whether the device runs iOS or iPad OS. In isIOS , we check navigator. platform or check whether there're more than 2 touch points max supported by the device.

How do I check the iOS version of a website?

For Mac devices go to the About Safari option from the Safari menu and for iOS devices go to the settings>General Settings>About. There are quite a few chances that you need to check the browser version on your iOS or Mac device.

How do I check JavaScript version on iPhone?

So all you need to do is test if it's an Iphone and then get the version: if ( isIphone() && iPhoneVersion() === "6"){ //code.. }


2 Answers

Please try this fiddle. It detects version of iPad by gyroscope availability.

As you can see in Safari Developer Library, event.acceleration is not null on devices that has a gyroscope. Since iPad 1 doesn't has it, we can assume that this device is iPad 1.

To distinguish iPad 2 from iPad 3, we can check a window.devicePixelRatio property, since iPad 3 has Retina display with pixel ratio == 2.

like image 179
Igor Shastin Avatar answered Oct 14 '22 07:10

Igor Shastin


Sorry but currently there is no difference between iPad and iPad 2.

See, there is no difference between the two of them:

iPad:
 Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5

iPad2:
 Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5

And notice there, that the versions there are constantly changing in iOS updates.

UPDATE

Looks like there is a difference between them:

iPad:
  Mobile/8F190

iPad 2:
  Mobile/8F191

iPad 3:
  Mobile/9B176 (according to Philipp)
like image 40
Derek 朕會功夫 Avatar answered Oct 14 '22 07:10

Derek 朕會功夫