Disable middle mouse click

倾然丶 夕夏残阳落幕 提交于 2019-12-19 10:52:09

问题


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.


回答1:


You can try with following:

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

Demo



来源:https://stackoverflow.com/questions/23886278/disable-middle-mouse-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!