2
votes

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: stackoverflow.com/a/37532486/3402854. Let me know if this solves your problem.cyberbit

1 Answers

0
votes

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.