Android vs. iPhone - Touch Events
While both Android and iPhone supposedly implement Apple’s touch events, there are several differences between the browsers. Here are a few I’ve noticed thus far:
Detecting Touch Event Support
- iOS invented
window.Touch
to check for touch event support, but this isn't supported on Android. window.TouchEvent
exists on iOS 4.x and Android, but not iOS 3.x.
The only reliable way I’ve found to determine touch event support is to use:
This is a way to do object detection for supported events on an object, and can be used for other events as well, such as onhashchange
in the window object to detect whether you listen for URL hash changes (useful for AJAX history).
Android (all versions)
- Android fires
touchmove
events at a regular (slower-than-iOS) interval as long as a finger is held down, even if the finger is not moving; iOS will fire events only when a finger moves.
Android 1.5-2.1
- Only three
touchmove
events fire while swiping one's finger, unlesspreventDefault()
is called during thetouchstart
event handler. (The rest are queued up, and all fire upon completion of the touch).
Android 1.5-1.6
- The
touches
array ontouchend
event objects contains the touch which has just completed. (The expected behavior is for thetouches
array to be empty).