TouchEvent: TouchEvent() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The TouchEvent() constructor creates a new TouchEvent object.

Note: If you construct a synthetic event using this constructor, that event will not be trusted, for security reasons. Only browser-generated TouchEvent objects are trusted and only trusted events trigger default actions.

Syntax

js
new TouchEvent(type)
new TouchEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers set it to touchstart, touchend, touchmove, touchcancel

options Optional

An object that, in addition of the properties defined in UIEvent(), can have the following properties:

touches Optional

A TouchList, defaulting to an empty one, that is a list of objects for every point of contact currently touching the surface.

targetTouches Optional

A TouchList, defaulting to an empty one, that is a list of objects for every point of contact that is touching the surface and started on the element that is the target of the current event.

changedTouches Optional

and defaulting to [], of type Touch[], that is a list of objects for every point of contact which contributed to the event.

ctrlKey Optional

A boolean value, defaulting to false, indicating if the ctrl key was simultaneously pressed.

shiftKey Optional

A boolean value, defaulting to false, indicating if the shift key was simultaneously pressed.

altKey Optional

A boolean value, defaulting to false, indicating if the alt key was simultaneously pressed.

metaKey Optional

A boolean value, defaulting to false, indicating if the meta key was simultaneously pressed.

Return value

A new TouchEvent object.

Specifications

Specification
Touch Events
# dom-touchevent-constructor

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
TouchEvent() constructor
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote
footnote Chrome only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote Edge only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote
footnote Opera only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote
footnote Chrome Android only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
Firefox for Android – Full support
Firefox for Android 46 (Release date: 2016-04-26)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote
footnote Opera Android only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote
footnote Samsung Internet only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote
footnote WebView Android only supports the following touchEventInit properties: touches, targetTouches, changedTouches.
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also

  • TouchEvent, the interface of the objects it constructs.