Skip to content Skip to sidebar Skip to footer

Disable Doubleclick Event For An Element In Opera

Is there a way to disable (with CSS, JS or jQuery) double-click for a given element? The problem with Opera is that it displays a menu when I click on an element too fast. Note tha

Solution 1:

It turended out I need this:

/**
    Disable text selection by Chris Barr, of chris-barr.com
*/
$.fn.disableTextSelect = function() {
    return this.each(function(){
        if($.browser.mozilla){//Firefox
            $(this).css('MozUserSelect','none');
        }else if($.browser.msie){//IE
            $(this).bind('selectstart',function(){return false;});
        }else{//Opera, etc.
            $(this).mousedown(function(){return false;});
        }
    });
}

And then I could disable text selection on my button elements like this:

$(function(){ $('input[type=image]').disableTextSelect(); });

And now I can click buttons fast as hell and all works fine :-).


Solution 2:

You cannot have a click and dblclick event handler attached on the same element because when you dblclick both the events are going to be triggered. In order to make it work there are few work arounds.

This might help you

Need to cancel click/mouseup events when double-click event detected

Looking at your problem there is a simple solution. In the click event handler once it is clicked set a disabled attribute or some class name(disabled). In the handler before exectuing your code checck for this attribute or class name. If it exists then dont do anything. After sometime remove this attribtue or class name. Try this

$("selector").click(function(){
   var $this = $(this);
   if(!$this.hasClass("disabled")){


       //Do you stuff here


       $this.addClass("disabled");

       setTimeout(function(){
         $this.removeClass("disabled");
       }, 200);  

   }
});

Solution 3:

JavaScript would do that for you.

DOMElement.ondblclick = (function () {return false;})();

Post a Comment for "Disable Doubleclick Event For An Element In Opera"