Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable the Mouse wheel click Button?

I'm trying to find a way of disabling the default action of the mouse wheel button which is to open the link in a new tab.

Is that possible?

like image 971
Déjà Bond Avatar asked Jul 09 '12 09:07

Déjà Bond


People also ask

How do I turn off the middle Mouse click?

If the middle mouse switch has an open spring, carefully bend the spring so it presses up against the wheel a bit harder. Alternatively, push a bit of springy closed-cell plastic foam between the switch and wheel so as to increase the force needed to depress the switch.


2 Answers

Bind a generic click event handler that specifically checks for middle clicks. Within that event handler, call e.preventDefault():

$("#foo").on('click', function(e) { 
   if( e.which == 2 ) {
      e.preventDefault();
   }
});

Note that not all browsers support preventing this default action. For me, it only works in Chrome. Firefox, Opera and IE9 all do not raise the click event with middle mouse click. They do raise mouseup and mousedown.

like image 63
J.P. ten Berge Avatar answered Oct 07 '22 04:10

J.P. ten Berge


This works for me...

$(document).on("mousedown", "selector", function (ev) {
    if (ev.which == 2) {
        ev.preventDefault();
        alert("middle button");
        return false;
    }
});
like image 43
A.T. Avatar answered Oct 07 '22 03:10

A.T.