简体   繁体   English

html href中的javascript函数调用无法与FireFox中的鼠标滚轮一起正常工作

[英]javascript function call in html href not working properly with the mouse wheel click in FireFox

I'm trying to call a javaScript function inside href attribute in html < a > tag. 我试图调用内部的JavaScript函数href在HTML属性< a >标签。

In Chrome it's working fine. 在Chrome中运行正常。 but in Firefox there is a problem. 但是在Firefox中存在问题。

It is not properly calling the function when we click the mouse wheel. 当我们单击鼠标滚轮时,它没有正确调用该函数。 Instead it will open a new browser tab with the href content. 相反,它将打开带有href内容的新浏览器选项卡。

use this fiddle example to view it. 使用此小提琴示例进行查看。 open it in firefox. 在Firefox中打开它。 It wont trigger the function when mouse wheel click. 鼠标滚轮单击不会触发该功能。

How can I overcome that and make it work. 我该如何克服它并使之发挥作用。

NOTE : The href url should be generated in that function which called by it. 注意:href网址应在其调用的函数中生成。

Use onclick to trigger functions, you can also use click event using id or class. 使用onclick触发功能,也可以使用id或class的click事件。

<a href="javascript:void(0)" onclick="return test()">Test</a>

using id 使用ID

  <a href="javascript:void(0)" id="clickme">Test</a>

jQuery jQuery的

$("#clickme").click(function(){
alert("executed");
});

For left, right or middle click you can use mousedown 对于左键,右键或中键,您可以使用mousedown

  • Left - 1 左-1
  • Middle - 2 中-2
  • Right - 3 右-3

$(document).mousedown(function(e){ switch(e.which) { case 1: //left Click break; case 2: //middle Click break; case 3: //right Click break; } return true;// to allow the browser to know that we handled it. });

EDIT I am afraid that right click or middle click on <a> tag is against firefox policy , to do so.. you have to change firefox settings. 编辑恐怕<a>标记上的右键单击或中键单击违反了Firefox 政策 ,要这样做,您必须更改Firefox设置。

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

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