Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected iOS Safari behaviour when dynamically updating viewport meta with JavaScript
    primarykey
    data
    text
    <p>I am adapting a website for iPhone iOS Safari browser. As I wish to make content takes whole viewport on both device orientations, I am making dynamic update of the <code>meta[name='viewport']</code> tag. </p> <p>Here's what I have set by default inside <code>meta[name='viewport']</code>:</p> <pre><code>&lt;meta name="viewport" content="width=device-width, initial-scale=0.51, minimum-scale=0.51, maximum-scale=0.51" /&gt; </code></pre> <p>Then, right after page is loaded, I am executing the following JavaScript code to make sure the entire viewport is occupied with the website and centered:</p> <pre><code>var viewport = $("html head meta[name='viewport']"); function switchViewport() { var wider = "0.765", shorter = "0.51"; switch (window.orientation) { case 0: case 180: viewport.attr("content", "width=device-width, initial-scale=" + wider + ", minimum-scale=" + wider + ", maximum-scale=" + wider + ""); break; case -90: case 90: viewport.attr("content", "width=device-width, initial-scale=" + shorter + ", minimum-scale=" + shorter + ", maximum-scale=" + shorter + ""); break; } } $(window).on("orientationchange", switchViewport); switchViewport(); </code></pre> <p>When I test on real iPhone (4, 4S) <strong>trying to rotate the device so 'onorientationchange' even is fired, it does exactly what I wished with a code above, except first turn</strong>. When I make first device rotation to change orientation, it doesn't render as I planned. However, when turning more times, it goes to normal. Just the first turn fails because of something.</p> <p>Here's a website: <a href="http://goo.gl/VXyBg" rel="nofollow">http://goo.gl/VXyBg</a> I am working on, so you can directly test with you real iPhone or just simulator. Better real one, as simulator doesn't give the same results comparing to real device for this special situation.</p> <p>If anyone faces similar situation or have knowledge, experience on where the problem could be, I would really appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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