TouchEvent: TouchEvent() constructor
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
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
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
TouchEvent |
48Chrome only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
79Edge only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
No |
No |
35Opera only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
No |
48Chrome only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
48Chrome only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
46 |
35Opera only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
3.2 |
5.0Samsung Internet only supports the following touchEventInit properties: touches , targetTouches , changedTouches .
|
See also
TouchEvent
, the interface of the objects it constructs.