pocketGod123
pocketGod123

Reputation: 27

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?

Upvotes: 0

Views: 2066

Answers (2)

bricksphd
bricksphd

Reputation: 177

For those looking for a pure-JS solution to this problem, the following also works:

document.addEventListener("contextmenu", function (e) {
  e.preventDefault()
  e.stopPropagation()
  console.log("Stopped")
  return false;
});

Upvotes: 0

Hazik Arshad
Hazik Arshad

Reputation: 514

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()

Upvotes: 2

Related Questions