Page is zoomed after change rotation to landscape on Android mobile devices

Viewed 2014

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 Answers

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.

Related