touchcancel event
Definition and Usage
The touchcancel event occurs when a touch event is interrupted.
Different devices may interrupt touch events in different actions, and if such a "mistake" 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 an 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>
Syntax
In HTML:
<element ontouchcancel="myScript">
In JavaScript:
object.ontouchcancel = myScript;
In JavaScript, use the addEventListener() method:
object.addEventListener("touchcancel", myScript);
Technical details
Bubbling: | Supported |
---|---|
Cancellable: | Supported |
Event types: | TouchEvent |
Supported HTML tags: | All HTML Elements |
Browser Support
The numbers in the table indicate the first browser version that fully supports the event.
Event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
touchcancel | 22.0 | 12.0 | 52 | Not Supported | Not Supported |