-1

I cannot seem to prevent TWO click events being fired when the user double-clicks an element. I've tried both jQuery (.click) and inline (onclick) handlers, and I have disabled the dblClick event using this:

$(window).ready(function() {
    $("*").on("dblclick", function(e){
        e.preventDefault();
        e.stopPropagation();
    });
});

I don't really want to add flag/timeouts everywhere as I have many click handlers and I need to disable double-clicks across the board generically...

JSFiddle here: https://jsfiddle.net/s0oteh84/26/

Simon Lobo
  • 39
  • 1
  • 4

3 Answers3

0

Use follwing:

$(document).ready(function() {
$("*").on("dblclick", function(e){
    return false;
});

});

vihar
  • 1
0

It's not even entering in your

$("*").on("dblclick", function(e){
        e.preventDefault();
        e.stopPropagation();
    });

better use timeout of around 300ms to differentiate between the clicks

Ashish Yadav
  • 3,039
  • 1
  • 16
  • 23
0

I fixed this by showing a temporary div above all the elements to receive the second click within a 400ms timeout.

jQuery("*").on("click", function(e){
  if (jQuery(this).attr('id') != "double_click_div") {
    jQuery('#double_click_div').css('display', 'block');
    setTimeout(function () {
      jQuery('#double_click_div').css('display', 'none');
    }, 400);
  }
  else
    alert('caught!');
});

https://jsfiddle.net/s0oteh84/34/

Simon Lobo
  • 39
  • 1
  • 4