It is necessary to distinguish between iPhone3x and iPhone4x. Is there a way to figure out the version from JavaScript please?
You can use navigator.userAgentthe OS version to check, but this is not a problem.
navigator.userAgent
What you can do is use media queries to check the actual screen resolution of the device, which may be causing the problem.
var isRetina = window.matchMedia("(-webkit-min-device-pixel-ratio: 2)").matches;
Perhaps you can also do without JavaScript by using media queries to load various stylesheets for retina displays:
<link rel="stylesheet" href="retina.css" media="only screen and (-webkit-min-device-pixel-ratio: 2)" />
This would be a combination of two methods in Javascript:
function iPhoneVersion() { var iHeight = window.screen.height; var iWidth = window.screen.width; if (iWidth === 320 && iHeight === 480) { return "4"; } else if (iWidth === 375 && iHeight === 667) { return "6"; } else if (iWidth === 414 && iHeight === 736) { return "6+"; } else if (iWidth === 320 && iHeight === 568) { return "5"; } else if (iHeight <= 480) { return "2-3"; } return 'none'; } function isIphone() { return !!navigator.userAgent.match(/iPhone/i); }
, , , , Iphone, :
if ( isIphone() && iPhoneVersion() === "6"){ //code.. }
. -, , javascript, , , , , iPhone 3GS -.
atornblad , , :
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { if (!(window.devicePixelRatio > 1)){ //non retina iphone / ipod } };
, iPod iPhone. Retina. iPhone 4+, .
- : "" , .
, : , . , , , , , , n. , 200 , , UX .
, , , .
, , navigator.appVersion.indexOf("... iphone3G Apple iOS 4.2.1 iphone4 4S Apple iOS 5.0.1, iphone3GS .
navigator.appVersion.indexOf("...
cpu, . - for (var i=0, k=1; i<5000000; i++) k++; , , .
for (var i=0, k=1; i<5000000; i++) k++;
iphone3G (S) 600 , iphone4 - 1 . , , () iphone.
, .
, , .
, - . , 0 10000000, . , , , .
, . . , .
iphone 4s < 200 iphone 4 <300 iphone 3gs <400 ipad 2 <200 all the rest are ipad 1
, , - :
var date1 = new Date();//time we started for (var i=0, j=1; i<10000000; i++) j++; var date2 = new Date();//time we ended diff=date2.getTime() - date1.getTime(); //time difference. alert(diff);//show me the difference so i can add lines to more phone types if (device=='iPad' && diff<200){ deviceVersion='2'; } else if (device=='iPad'){ deviceVersion='1'; } else if (device=='iphone' && diff<200){ deviceVersion='4s'; } else if (device=='iphone' && diff<300){ deviceVersion='4'; } else if (device=='iphone' && diff<400){ deviceVersion='3gs'; } ...
. , .