This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

pointerType

Summary

Indicates the device type that caused the event (mouse, pen, touch, etc.).

Property of dom/PointerEventdom/PointerEvent

Syntax

Note: This property is read-only.

var result = event.pointerType;

Return Value

Returns an object of type StringString

Examples

Detecting the type of input from a user

window.addEventListener("pointerdown", detectInputType, false);
function detectInputType(event) {
    switch(event.pointerType) {
        case "mouse":
            alert("You used a mouse!");
            break;
        case "pen":
            alert("You used a pen stylus!");
            break;
        case "touch":
            alert("You used touch!");
            break;
        default:
            alert("Not sure what device was used!");
    }
}

Usage

 If a user agent is to fire a pointer event for a mouse, pen stylus, or touch input device, then the value of pointerType must be according to the following table:
Pointer Device TypepointerType Value
Mousemouse
Pen Styluspen
Touch Contacttouch

If the device type cannot be detected by the user agent, then the value must be an empty string. If a user agent supports pointer device types other than those listed above, the value of pointerType should be vendor prefixed to avoid conflicting names for different types of devices. Future specifications may provide additional normative values for other device types.

Notes

In Internet Explorer 11, this property has been changed to return a string value. In Internet Explorer 10, it provided a return type of long: •MSPOINTER_TYPE_TOUCH: 0x00000002 •MSPOINTER_TYPE_PEN: 0x00000003 •MSPOINTER_TYPE_MOUSE: 0x00000004

Attributions