BreakPhreak BreakPhreak - 1 month ago 5
Javascript Question

How to determine which iPhone version the javascript code runs on?

Need to distinguish between iPhone3x and iPhone4x. Is there any way to figure out the version from JavaScript please?


You can use navigator.userAgent to check the OS version, but that isn't really the problem here.

What you can do is use media queries to check the actual screen resolution of the device, which might be the cause of the problem at hand.

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

You could also probably do without JavaScript, by using media queries for loading different stylesheets for retina displays:

<link rel="stylesheet" href="retina.css"
    media="only screen and (-webkit-min-device-pixel-ratio: 2)" />