简体   繁体   English

在 Firefox 中禁用鼠标中键

[英]Disable mouse middle click in Firefox

Anchor tag is opening in new window while we have clicked middle button of mouse.当我们点击鼠标中键时,锚标签在新窗口中打开。 I want to disable this new window/tab.我想禁用这个新窗口/选项卡。 The belwo provided code is working in chrome. belwo 提供的代码在 chrome 中工作。

$("a").on('click', function(e) { 
   if( e.which == 2 ) {
      e.preventDefault();
   }
}); 

Checked following links:检查了以下链接:

  1. Triggering onclick event using middle click 使用中键触发 onclick 事件
  2. Disable middle mouse button for modal dialog 禁用模式对话框的鼠标中键

According to some better is to change anchor tag to some other tabs, but I need the default behavior of anchor tab in left click, I need to disable middle and right clicks.根据一些更好的方法是将锚标记更改为其他一些选项卡,但我需要在左键单击时锚选项卡的默认行为,我需要禁用中键和右键单击。 Somebody help me to solve this.有人帮我解决这个问题。

Note: Many questions are asked regarding the same, but this exact issue is not yet asked.注意:很多问题都被问到了,但这个确切的问题还没有被问到。

This is not working in Firefox.这在 Firefox 中不起作用。 I need to solve this issue in Firefox too.我也需要在 Firefox 中解决这个问题。

fiddle小提琴

This is for blocking middle clicking entire document on firefox.这是为了阻止在 Firefox 上单击整个文档。 You can check whatever element by e.target.您可以通过 e.target 检查任何元素。 Its need jQuery, but u could also use vanilla js它需要 jQuery,但你也可以使用 vanilla js

$(document).on('auxclick', function(e) {
    if( e.button == 1 ) 
    alert('Its blocked globally');
    e.preventDefault();
    return false;
  }
})

纯 html 解决方案,没有 javascript:

<a href="javascript:void(0)" onclick="window.location = 'http://www.stackoverflow.com';">Click me</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM