Search code examples
javascriptiosdom-eventsios-simulatoriphone-4

ontouch function not being fired on iPhone simulator


On the iPhone Simulator, the event callback for ontouch doesn't seem to be working.

The following does not seem to work on my simulator:

document.ontouch = function() {
    alert('it works!');
}

Although this does return true:

if ('ontouch' in document) {
    alert('touch supported');
}

Has anyone else had this issue?


Solution

  • There are 3 touch related events:

    1. ontouchstart
    2. ontouchmove
    3. ontouchend

    Try it with these and it should be OK!

    Some good examples can be found with this article:

    http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/