1

In the following code I have a simple "taphold" event defined, so summon an alert with some text. The problem is that a simple tap will trigger this event as well. The point is that the user has to hold the tap to proceed (in this case alert a text).

What is causing this behavior?

$("#button").on("taphold", function() {
  alert("Good day, sir!");
});

So as mentioned before, a single tap will trigger this event. How can I prevent this from happening?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jorrex
  • 1,503
  • 3
  • 13
  • 32
  • Do you want a solution that doesn't include jQuery? It just JavaScript. One thing about taphold it only last for about one second and then fires the event. – dowomenfart Feb 26 '15 at 14:13
  • I need a solution that includes a taphold, I don't care if it is jQuery or pure Javascript ;) I'm working on a project that has to prevent from people touching the screen (tapping) and executing a function. So the taphold would prevent this, except for the fact it is acting like a single tap at this moment. – Jorrex Feb 26 '15 at 14:20
  • Try this http://jsfiddle.net/re18ssyn/ – dowomenfart Feb 26 '15 at 16:03

1 Answers1

0

This works for me in Cordova Android

var pressTimer

$("a").on("mouseup touchstart", function () {
    clearTimeout(pressTimer)
    // Clear timeout
    return false;
}).on("mousedown touchstart", function () {
    // Set timeout
    pressTimer = window.setTimeout(function () {
        alert("hi");
    }, 1000)
    return false;
});
Alex
  • 1