2

I need your help in one question that how to disable the middle mouse click on any link to open a new tab in IE 7,8,9. I have tried many thing like

return false;
e.cancelBubble = true;e.returnValue = false;

But not able to stop that feature of IE to open New tab.But if i am putting alert message e

if (event.button == 4)
    {
alert("shashank");
}

I am able to stop to open new tab .But I don't want to use alert message.

Toni Toni Chopper
  • 1,833
  • 2
  • 20
  • 29
Ethan Hunt
  • 33
  • 1
  • 3
  • Check this out http://stackoverflow.com/questions/16498092/mouse-disable-right-and-middle-button-click http://stackoverflow.com/questions/11392318/how-to-disable-the-mouse-wheel-click-button – Jakobbbb May 27 '14 at 09:57

2 Answers2

6

None of the answers above worked for me. According to MDN the auxclick event is the proper way to do this.

The following code will prevent the middle click behaviour on the entire page.

window.addEventListener("auxclick", (event) => {
  if (event.button === 1) event.preventDefault();
});
Robbendebiene
  • 4,215
  • 3
  • 28
  • 35
2

You can try with following:

$(document).mousedown(function(e){
    if(e.which === 2 ){
       alert("middle click");    
       return false; // Or e.preventDefault()
    }
});

Demo

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68