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?
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.
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.
So all you need to do is test if it's an Iphone and then get the version: if ( isIphone() && iPhoneVersion() === "6"){ //code.. }
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.
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.
Looks like there is a difference between them:
iPad:
Mobile/8F190
iPad 2:
Mobile/8F191
iPad 3:
Mobile/9B176 (according to Philipp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With