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/SolutionDet
Detect between iPad 1 and 2 Steps:
Detect between iPad 2 and 3 Steps:
Detect between iPad 3 and 4 Steps:
Maximum Anisotropy of 16 usually indicates a modern device with decent graphics performance.
var gl;
var iPadVersion = false;
window.ondevicemotion = function(event) {
if (!iPadVersion && navigator.platform.indexOf("iPad") != -1) {
iPadVersion = 1;
if (event.acceleration) iPadVersion = window.devicePixelRatio;
}
window.ondevicemotion = null;
}
function initWebGL(canvas) {
gl = null;
try {
gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
}
catch(e) {}
if (!gl) {
gl = null;
}
return gl;
}
function checkMaxAnisotropy() {
var max = 0;
var canvas = document.getElementById('webGLCanvasTest');
gl = initWebGL(canvas);
try {
gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
}
catch(e) {}
if (gl) {
var ext = (
gl.getExtension('EXT_texture_filter_anisotropic') ||
gl.getExtension('MOZ_EXT_texture_filter_anisotropic') ||
gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic')
);
if (ext){
max = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
}
}
return max;
}
function isiPad( $window ) {
var ua = $window.navigator.userAgent || $window.navigator.vendor || $window.opera;
return (/iPad/).test(ua);
}
function getiPadVersion( $window ) {
if(isiPad(window) && window.devicePixelRatio === 2) {
if(checkMaxAnisotropy() < 4) {
iPadVersion = 3;
} else {
iPadVersion = 4;
}
}
return iPadVersion;
}
/* BONUS CODE
isSmartDevice() - Detect most mobile devices
isOldDevice() - Detect older devices that have poor video card performance
*/
function isSmartDevice( $window ) {
var ua = $window.navigator.userAgent || $window.navigator.vendor || $window.opera;
return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
}
function isOldDevice() {
if(isSmartDevice(window) && window.devicePixelRatio === 1 && checkMaxAnisotropy() < 4 || isiPad( window ) && checkMaxAnisotropy() < 4) {
return true;
} else {
return false;
}
}
alert('iPad Version: ' + getiPadVersion(window) );
#webGLCanvasTest {
width: 1px;
height: 1px;
position: fixed;
top: -1px;
left: -1px;
}