Preventing the touch events’ default action

Returning false, or calling preventDefault(), in an event handler is supposed to prevent the default action of the event. So if a user clicks a link the link is not followed, if the user scrolls nothing actually happens, etc. Does this work everywhere for the touch events? My latest research gives the details.

I studied touchstart and touchmove for five actions: tap (click), double tap, scroll, pinch-zoom, and touchhold. Also I took a look at the event cascade. It, too, should be cancelled when you prevent the default.

It turns out that theory is sensible, and all major browsers obey theory. Tap, double tap, and touchhold depend only on the touchstart event, and are only prevented when you return false ontouchstart. So is the event cascade. Scroll and pinch-zoom depend on both touchstart and touchmove, and are therefore prevented when you return false on either event.

Of course plenty of browsers, especially minor ones, have problems:

Have fun with the full table.

This is the blog of Peter-Paul Koch, web developer, consultant, and trainer. You can also follow him on Twitter or Mastodon.
Atom RSS

If you like this blog, why not donate a little bit of money to help me pay my bills?

Categories: