Detect iOS device model name using JavaScript
+ View JavaScript source
function iOSdeviceDetection(){
var ua = navigator.userAgent;
if( /iPhone/.test(ua) ){
if( screen.width*16 - screen.height*9 == 0 ) return 'iPhone 5';
if( window.devicePixelRatio == 2 ){
switch( getOSmajorver(ua) ){
case 4:
return 'iPhone 4';
case 5:
case 6:
return 'iPhone 4 or 4S';
default:
return '?';
}
}
switch( getOSmajorver(ua) ){
case 1:
return 'iPhone(1st)';
case 2:
return 'iPhone(1st) or 3G';
case 3:
case 4:
return 'iPhone(1st), 3G or 3GS';
case 5:
case 6:
return 'iPhone 3GS';
default:
return '?';
}
}
if( /iPad/.test(ua) ){
if( window.devicePixelRatio == 2 ){
switch( getOSmajorver(ua) ){
case 5:
return 'iPad(3rd)';
case 6:
return 'iPhone(3rd) or (4th)';
default:
return '?';
}
}
switch( getOSmajorver(ua) ){
case 3:
return 'iPad(1st)';
case 4:
case 5:
return 'iPad(1st) or iPad 2';
case 6:
return 'iPad 2 or mini';
default:
return '?';
}
}
if( /iPod/.test(ua) ){
if( screen.width*16 - screen.height*9 == 0 )return 'iPod touch(5th)';
if( window.devicePixelRatio == 2 ) return 'iPod touch(4th)';
switch( getOSmajorver(ua) ){
case 1:
return 'iPod touch(1st)';
case 2:
return 'iPod touch(1st) or (2nd)';
case 3:
return 'iPod touch(1st), (2nd) or (3rd)';
case 4:
return 'iPod touch(2nd) or (3rd)';
case 5:
return 'iPod touch(3rd)';
default:
return '?';
}
}
return 'not iOS device';
function getOSmajorver( ua ){
if( /OS 6/.test(ua) )return 6;
if( /OS 5/.test(ua) )return 5;
if( /OS 4/.test(ua) )return 4;
if( /OS 3/.test(ua) )return 3;
if( /OS 2/.test(ua) )return 2;
return 1;
}
}
+ Description