touchcancel event

Definition and usage

The touchcancel event occurs when a touch event is interrupted.

Different devices may interrupt touch events in different actions, if such an "error" occurs, it is considered a good habit to include this event to clean up the code.

Note:The touchcancel event is only applicable to devices with touchscreens.

Tip:Here are other events related to the touchcancel event:

  • touchstart - Occurs when the user touches an element
  • touchend - Occurs when the user removes a finger from the element
  • touchmove - Occurs when the user moves a finger on the screen

Example

Execute JavaScript when a touch is interrupted (only for touchscreens):

<p ontouchcancel="myFunction(event)">Touch me!</p>

Try it yourself

Syntax

In HTML:

<element ontouchcancel="myScript">

Try it yourself

In JavaScript:

object.ontouchcancel = myScript;

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("touchcancel", myScript);

Try it yourself

Technical details

Bubbling: Supported
Cancellable: Supported
Event types: TouchEvent
Supported HTML tags: Alle HTML elementer

Browserunderstøttelse

Tallene i tabellen angiver den første browserversion, der fuldt ud understøtter denne begivenhed.

Begivenheder Chrome IE Firefox Safari Opera
touchcancel 22.0 12.0 52 Ikke understøttet Ikke understøttet