Delen via


Making touch events accessible

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

For technical reasons, HTML touch events such as pointerUp aren't programmatically accessible by default. To make them accessible, and to allow Narrator touch gestures to activate your app's functionality, add code to hook touch events to the click event, which is programmatically accessible by default.

element.addEventListener("click", onClick);
element.addEventListener("PointerUp", onPointerUp);

...

var pointerUpEventObject = null;
var pressedElement = null;
var isUiaClick = false;

function onClick(evt) {
    isUiaClick = true;
    delayedPointerUp();
}

function onPointerUp(evt) {
    pointerUpEventObject = evt;
    setImmediate(delayedPointerUp);
}

...

function delayedPointerUp() {
    if (isUiaClick || pointerUpEventObject && 
            (pointerUpEventObject.srcElement == pressedElement || 
            ...right button checks...)) {
        pointerUpEventObject = null;
        isUiaClick = false;
        invokeItem(pressedElement);
    }
}

...