2

I have a javascript confirm dialog popping up, but when I tap 'Cancel', then after the dialog closes, tap anywhere on the screen, the dialog pops up again. It only happens the one extra time, then you can tap on the page again without the dialog popping up.

I'm only seeing this on iPhone/iPad running iOS 5.0.1. I don't have an iOS 6 device, so I'm not sure it's happening there.

Here's the code I'm using:

$(bpm.remoteAppDivName).on('tap', 'a.delete-pending-payment', function(event) { 

    if  (isJQMGhostClick(event)) { return false; }

    var deleteGlobalPaymentURL = $(this).attr('href');

    var confirmMsg = confirm ("Are you sure you want to do that?"); 

    if (confirmMsg === true){

        window.location = '/index.htm';

    }
    event.preventDefault();
    return false;

});

var lastclickpoint, curclickpoint;
var isJQMGhostClick = function(event){
    curclickpoint = event.clientX+'x'+event.clientY;
    var ret=false; 
    if (lastclickpoint === curclickpoint) {
        ret=true;
    } else {
        ret=false;
    }
    lastclickpoint = curclickpoint;
    return ret;
}

Here's a link to the problem page: http://www.5280skateparks.com/dev/confirmBug.htm

Any help would be extremely appreciated.

UPDATE: I just confirmed that it's happening on iOS 6.0.1 as well.

haddnin
  • 550
  • 4
  • 10

1 Answers1

0

This is the jQuery Mobile "Ghost Click" discussed in some detail here and here. On the forum page, a solution was proposed, which I have reproduced below with a small bug fix:

var lastclickpoint, curclickpoint;
var isJQMGhostClick = function(event){
    curclickpoint = event.clientX+'x'+event.clientY;
    var ret=false; 
    if (lastclickpoint === curclickpoint) {
      ret=true;
    } else {
      ret=false;
    }
      lastclickpoint = curclickpoint;
   return ret;
}

I have modified this code slightly to not always expect a pair of clicks. This function now works correctly in the case of 0 ghost clicks and more than 2 ghost clicks. You can use it by checking isJQMGhostClick(event) at the beginning of your tap handler and ignoring the event if the isJQMGhostClick function returns true.

  • Thanks for the fast response. I'll try out your solution first thing Monday morning and report back. Have a great weekend. – haddnin Feb 02 '13 at 17:06
  • I implemented your solution and I'm getting the same issue. I'm wondering if this is indeed the "Ghost Click" mentioned above or maybe I implemented it incorrectly. You can see the problem still exists here: http://www.5280skateparks.com/dev/confirmBug.htm I edited the original post to include your proposed solution. – haddnin Feb 04 '13 at 17:47
  • Can you try `return false` instead of return in the ghost click check, and add a return false after preventDefault? – Spathi Wankenstein Feb 05 '13 at 04:57
  • I tried adding `return false` where you mentioned, but still not working. I ended up using this solution: http://stackoverflow.com/a/10364437/1720446 The only thing I don't like about that solution is that I couldn't use `tap` as an event. I had to use `touchstart` **and** `click`. Again, I edited the OG post to include your changes. – haddnin Feb 05 '13 at 20:22