Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A better way to do this is to use media targeting, rather than JavaScript.</p> <p>Done correctly, the iPhone will only ever retrieve the image appropriate to its screen size and pixel ratio, so there is no need to resort to JavaScript.</p> <h1>Media Targeting</h1> <p>This works for iPhones;</p> <pre><code>&lt;!-- iPhone 2G, 3G, 3GS --&gt; &lt;link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px)" href="apple-touch-startup-image-320x460.png"&gt; &lt;!-- iPhone 4, 4S --&gt; &lt;link rel="apple-touch-startup-image" media="(-webkit-device-pixel-ratio: 2) and (device-width: 320px) and (device-height: 480px)" href="apple-touch-startup-image-640x920.png"&gt; &lt;!-- iPhone 5 --&gt; &lt;link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px)" href="apple-touch-startup-image-640x1096.png"&gt; </code></pre> <p>And for iPads;</p> <pre><code>&lt;!-- iPad 1, 2, Mini - Portrait --&gt; &lt;link rel="apple-touch-startup-image" media="(device-width: 768px) and (orientation: portrait)" href="apple-touch-startup-image-768x1004.png"&gt; &lt;!-- iPad 1, 2, Mini - Landscape --&gt; &lt;link rel="apple-touch-startup-image" media="(device-width: 768px) and (orientation: landscape)" href="apple-touch-startup-image-1024x748.png"&gt; &lt;!-- iPad 3, 4 - Portrait --&gt; &lt;link rel="apple-touch-startup-image" media="(-webkit-device-pixel-ratio: 2) and (device-width: 768px) and (orientation: portrait)" href="apple-touch-startup-image-1536x2008.png"&gt; &lt;!-- iPad 3, 4 - Landscape --&gt; &lt;link rel="apple-touch-startup-image" media="(-webkit-device-pixel-ratio: 2) and (device-width: 768px) and (orientation: landscape)" href="apple-touch-startup-image-2048x1496.png"&gt; </code></pre> <p>More information on these startup images can be found at <a href="http://stuffandnonsense.co.uk/blog/about/home-screen-icons-and-startup-screens" rel="nofollow">Stuff &amp; Nonsense</a>.</p> <p>This will cause the device to download only the image appropriate to it.</p> <h1>Measuring device height in JavaScript</h1> <p>If you <em>must</em> use JavaScript for any reason (and I do advise against it), you can retrieve the device's height with <code>window.screen.height</code>. On 3.5-inch devices, it will be <code>480</code>, and on 4-inch devices, it is <code>568</code>.</p> <p>For more information on measuring the viewport in JS, see <a href="http://responsejs.com/labs/dimensions/" rel="nofollow">ResponseJS' guide</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload