简体   繁体   中英

How to distinguish between iPhone 4 and iPhone 4s in javascript

I have an app which can only run from iPhone 4s and up, I need to be able to distinguish on the client side (ie javascript) the device, and load the app or redirect accordingly. Is there any way to detect it? thanks

I see these three options for you:

1) use a precooked open source script to check this and based on the result you do a redirect. You can use this for example: http://detectmobilebrowsers.com/

2) you implement a javascript which do a checking based on the navigator parameters. See this and a quote code from that SO answer.

 function iOSversion() { if (/iP(hone|od|ad)/.test(navigator.platform)) { var v = (navigator.appVersion).match(/OS (\\d+)_(\\d+)_?(\\d+)?/); return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; } } 

3.) you can use rewrite rules at Apache side to redirect to the proper page based on user-agent. See this .

For all 3 options you have a problem that it is hardly possible to distinguish between iPhone 4 and 4s. See this SO answer .

To mention only if you have to check retina capability you can use this JS too:

var isRetina = window.matchMedia("(-webkit-min-device-pixel-ratio: 2)").matches;

More info what is min-device-pixel-ratio here: link . Also info on media queries here: link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM