W3cubDocs

/DOM

PointerEvent.pointerType

The pointerType read-only property of the PointerEvent interface indicates the device type that caused the pointer event. The supported values are the following strings:

mouse
The event was generated by a mouse device.
pen
The event was generated by a pen or stylus device.
touch
The event was generated by a touch such as a finger.

If the device type cannot be detected by the browser, the value can be an empty string (""). If the browser supports pointer device types other than those listed above, the value should be vendor prefixed to avoid conflicting names for different types of devices.

Syntax

var pType = pointerEvent.pointerType;

Return value

pType
The event's pointer type, either the string mouse, pen or touch.

Example

This example illustrates using the value of the pointerType to call the appropriate pointer type processing function.

targetElement.addEventListener("pointerdown", function(ev) {
   // Call the appropriate pointer type handler
   switch (ev.pointerType) {
     case "mouse": 
       process_pointer_mouse(ev); 
       break;
     case "pen": 
       process_pointer_pen(ev); 
       break;
     case "touch": 
       process_pointer_touch(ev); 
       break;
     default:
       console.log("pointerType " + ev.pointerType + " is Not suported");
   }
 }, false);

Specifications

Specification Status Comment
Pointer Events
The definition of 'pointerType' in that specification.
Recommendation Initial definition.
Pointer Events – Level 2
The definition of 'pointerType' in that specification.
Working Draft Non-stable version.
CSS Object Model (CSSOM) View Module
The definition of 'MouseEvent' in that specification.
Working Draft Redefines MouseEvent from long to double. This means that a PointerEvent whose pointerType is mouse will be a double.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 55 (Yes) (Yes) [1] 10 42 No support
mouse type pointers are double 56 (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support 55 55 (Yes) No support No support 10 42 No support
mouse type pointers are double 56 56 (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

[1] This feature is currently hidden behind a flag; to enable it and experiment, set the dom.w3c_pointer_events.enabled preference to true in about:config.

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType