开发者

Disable doubleclick event for an element in Opera

开发者 https://www.devze.com 2023-03-31 12:33 出处:网络
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 that I know how to dis

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 that I know how to disable this for me. I'd like to be able to disable this for all user that use the script.

The buttons in question are "next"/"previous" buttons and I use input type image for them, but the same happens开发者_StackOverflow中文版 with "a".


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 :-).


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);  

   }
});


JavaScript would do that for you.

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

精彩评论

暂无评论...
验证码 换一张
取 消