How to Disable the Mouse wheel click Button?

Déjà Bond picture Déjà Bond · Jul 9, 2012 · Viewed 20.4k times · Source

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?

Answer

J.P. ten Berge picture J.P. ten Berge · Jul 9, 2012

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.