Double Click JavaScript Lock

I am currently working on a slide gallery. My problem is that when I click on the navigation divs very quickly, the default behavior for browsers is triggered (content selection).

My question is: how can I suppress default double click behavior?

navigationDiv.onclick = function () {
  // do something
};

JQuery solution would also be suitable since I use it.

Thanks in advance!

+3
source share
8 answers
$("yourselector").dblclick(function(){
    return false;
});

You can also use event.preventDefault ()

$("yourselector").dblclick(function(event){
    event.preventDefault();
});
+7
source

You can try to disable the onselectstart event of the target element.

navigationDiv.onselectstart=function(){return false}

Not sure if this is compatible with x-browser. (I'll check it)

Edit
, IE. Mozilla, CSS- -moz-user-select. JavaScript, :

navigationDiv.style.MozUserSelect="none"

, , , .

+3

FYI, Firefox Safari/Chrome, CSS:

.navigationDiv {
    -moz-user-select: none;             
    -webkit-user-select: none;  
}

, , , .

+3

return false; .

+1

dblclick false false?

 $('.someStuff').bind('dblclick', function() { return false; });
0

ondblclick:

navigationDiv.ondblclick = function () { 
  return false;  // cancel default
}; 

http://www.quirksmode.org/js/events_mouse.html

0

:

navigationDiv.ondblclick = function (event) {
  // do something
  if (!event) event = window.event;
        if (event.preventDefault) 
            event.preventDefault();
        else 
            event.returnValue = false;

};

IE Mozilla.

0

event.preventDefault() dblclick- , BEING CLICKED, .

, , . 2 :

  1. , : window.getSelection(). Empty(). , , Opera ("", "").
  2. e.PreventDefault() dblclick.
0

Source: https://habr.com/ru/post/1736472/


All Articles