Search code examples
javascriptevent-handlingmouseevent

Disable middle mouse click


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.


Solution

  • You can try with following:

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

    Demo