4

How to avoid page zooming after changing rotation from Portrait to landscape? The problem appears on Mobile Android devices if content is larger then device width (I could not limit or scale image, scroll should appear).

Content of viewport meta tag is set as "width=device-width, initial-scale=1.0".

Is any way to fix this problem besides using "user-scalable=no or maximum/minimum-scale=1"?

  • 1
    Check out my answer to a similar question here: http://stackoverflow.com/a/37532486/3402854. Let me know if this solves your problem. – cyberbit May 30 '16 at 19:28
  • 1
    Possible duplicate of [The values of meta viewport attribute are not reflected when in full screen mode in android chrome browser](https://stackoverflow.com/questions/47954761/the-values-of-meta-viewport-attribute-are-not-reflected-when-in-full-screen-mode) – Agnel Vishal Mar 19 '18 at 11:18

1 Answers1

0

I bumped into this problem and was able to solve it by overwriting on rotate the initial-scale value from 1 to 1.001. This effectively forces whatever Android browser you're using to redraw the page and since the values are so close they will look practically identical.

let _AndroidDevice = navigator.userAgent.includes('Android');
let metaViewport = $('meta[name=viewport]').attr('content');

if (_AndroidDevice){

    if (metaViewport.includes('initial-scale=1.001')) {
        metaViewport = metaViewport.replace('initial-scale=1.001', 'initial-scale=1.0');
    } else {
        metaViewport = metaViewport.replace('initial-scale=1.0', 'initial-scale=1.001');
    }

    $('meta[name=viewport]').attr('content', metaViewport);
}

Hope this helps.

marcel_pi
  • 375
  • 1
  • 3
  • 7