Skip to content

Instantly share code, notes, and snippets.

@PGMY
Created April 12, 2013 02:49
Show Gist options
  • Save PGMY/5368928 to your computer and use it in GitHub Desktop.
Save PGMY/5368928 to your computer and use it in GitHub Desktop.
JSでiOSのデバイス判定してみたり ref: http://qiita.com/items/ad5236b06d2029e8fb1c
function getDevice(){
var ua = navigator.userAgent;
var device = 0;
if(ua.match(/iPhone/i)) device = 1;
if(ua.match(/iPad/i)) device = 2;
if(ua.match(/iPod/i)) device = 3;
switch (device ) {
case 1:
if( window.devicePixelRatio >= 2 ) {
if ( screen.height >= 568 ) return "iPhone5";
else return "iPhone4/4S";
} else {
return "iPhone3/3S"
}
break;
case 2:
if( window.devicePixelRatio >= 2 ) {
return "iPad2"
} else {
return "iPad/mini"
}
break;
case 3:
if( window.devicePixelRatio >= 2 ) {
if ( screen.height >= 568 ) return "iPod5";
else return "iPod4";
} else {
return "iPod3"
}
default:
return "NotiOS";
}
return "Error";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment