javascriptevent-handlingdom-eventstouch-eventresponsiveness

Disable options on long touch event


In my JS I have an image with an event listener of touchstart and touchend. touching the image manipulates a part of the HTML. in a way that as long as the user holds the finger on the image the desired manipulation continues to accrue.

The problem I'm facing (at least with android) is that when the user holds the finger on the image for more than 2 seconds, a popup window appears and asks if you'd wish to download the image.

Obviously the pop-up belongs to the mobile operating system - so how I can prevent this from happening?


Solution

  • You can use this event to stop long touch

    $(document).on('contextmenu', function (e) {
                    return false;
                });
    

    OR

    Javascript has a function to prevent the default action of a browser for the event in question.

    event.preventDefault()