Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent default double-tap behavior (zooming, panning) in Mobile Safari on iOS4?

When I double-tap near the edge of a page that exceeds the height or width of the browser window in Safari under iOS4, it zooms in or out and/or scrolls up, down, right, or left, depending on the size of the page and the current viewport position. How can I prevent this behavior, please?

I'm working on a site where this is (very) bad; we're preserving several layers of menu state and scrolling horizontally to navigate between layers. Double-tapping hoses the layout, and there's no intuitive way to get it back.

Double-tap does not seem to fire a scroll or touch event as far as I can tell. Other things I've tried:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />

... with variations:

  • user-scalable=no
  • user-scalable=0
  • width=device-width
  • width=320
like image 439
Kent Brewster Avatar asked Jul 28 '10 16:07

Kent Brewster


3 Answers

It looks like making absolutely certain that none of my important elements--I have a static header, scrolling body, and static footer, and the header and body can both scroll sideways--actually exceed the viewport width and have overflow:hidden seems to have done the trick.

Very sad there's nothing official on this, because it's annoying, and breaks most of the other examples I've found online

like image 51
Kent Brewster Avatar answered Nov 18 '22 23:11

Kent Brewster


You have a small typo in you meta tag, between each setting you should use comma. ex.

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
like image 2
Bjarne Mogstad Avatar answered Nov 19 '22 00:11

Bjarne Mogstad


I find that the <meta name="viewport" ...> tag generally works on iOS to prevent scaling with double-tap but on the iPad3 on iOS 5.1 there are occasional rare circumstances, which I have difficulty reproducing, where the double-tap zoom gets activated and subsequently screws up the page layout. The behavior is quite buggy. Perhaps using Javascript to manage tap events can help to prevent this from happening while we wait for Apple to fix this. It's difficult to test without having a way to reproduce the bug though.

Disclaimer: I have not tested this method.

like image 1
Steven Lu Avatar answered Nov 19 '22 00:11

Steven Lu