Disable middle mouse click

后端 未结 2 343
天涯浪人
天涯浪人 2021-01-16 05:08

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          


        
相关标签:
2条回答
  • 2021-01-16 05:46

    You can try with following:

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

    Demo

    0 讨论(0)
  • 2021-01-16 06:01

    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();
    });
    
    0 讨论(0)
提交回复
热议问题