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.Touchto check for touch event support, but this isn't supported on Android.
window.TouchEventexists 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:
if ('ontouchstart' in document)
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
touchmoveevents 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.
- Only three
touchmoveevents fire while swiping one's finger, unless
preventDefault()is called during the
touchstartevent handler. (The rest are queued up, and all fire upon completion of the touch).
touchendevent objects contains the touch which has just completed. (The expected behavior is for the
touchesarray to be empty).