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"?

2

1 Answer 1

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.

1
  • Would that work for iOS as well? Commented Oct 27, 2021 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.