Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS iPad zoom problems Re: iPad zoom problems

#86802
benjamincharity
Participant

I’ve seen many issues in responsive designs where rotating the device screws up the zoom level due to iOS not understanding the device width change.

Running some tests showed that even when rotated the device, iOS was still registering the initial width.

Here is a javascript hack that I’ve seen used which, via the meta viewport tag, disables zooming during the rotation and re-enables it when a user tries to zoom.


if (navigator.userAgent.match(/iPhone/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'maximum-scale=1';
// When someone touches it, let them scale it
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=980, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}

(Sorry about the crappy indention, I’m not sure how to enable that in the comments)

Not saying this is the best solution; but it is a solution.