Preventing mouse emulation events (ie click) from touch events in Mobile Safari / iPhone using Javas

Posted by Jaime Cham on Stack Overflow See other posts from Stack Overflow or by Jaime Cham
Published on 2010-05-23T06:58:47Z Indexed on 2010/05/23 7:00 UTC
Read the original article Hit count: 455

In doing a single page Javascript app with interactive DOM elements I've found that the "mouseover-mousemove-mousedown-mouseup-click" sequence happens all in a bunch after the "touchstart-touchmove-touchend" sequence of events.

I've also found that it is possible to prevent the "mouse*-click" events from happening by doing an "event.preventDefault()" during the touchstart event, but only then, and not during the touchmove and touchend. This is a strange design, because because it is not possible to know during the touchstart yet whether the user intents to drag or swipe or just tap/click on the item.

I ended up setting up a "ignore_next_click" flag somewhere tied to a timestamp, but this is obviously not very clean.

Does anybody know of a better way of doing this, or are we missing something?

Note that while a "click" can be recognized as a "touchstart-touchend" sequence (ie no "touchmove"), there are certain things, such as keyboard input focus, that can only happen during a proper click event.

© Stack Overflow or respective owner

Related posts about javascript-events

Related posts about iphone-web