disable long-press vibration in javascript for iOS

working on a webgame with ThreeJS. On iOS, a longpress creates a small haptic vibration feedback after 0.5s have passed.

Since I'd like the user to be able to hold their finger down to walk around, this is a distraction.

I've already got preventDefault and stopPropagation in play for touchStart, touchEnd, touchMove, touchCancel, and contextMenu, what am I missing?

Each are implemented as such:

function onTouchStart(event) {
     event.preventDefault();
     event.stopPropagation();
     ...

Thanks!


Solution 1:

It seems that you have to explicity select a container and attach the event handling to that cotainer.

HTML:

<body><div id="body">
    <div>
        test
    </div>
</div></body>

Javascript:

document.getElementById('body').addEventListener("touchstart", (e)=>{
    e.preventDefault();
    e.stopPropagation();
});

Example that works when attaching to the #body div : https://jsfiddle.net/gyfbh35t/2/

Example that does not work when attaching to the document: https://jsfiddle.net/gyfbh35t/3/