I'm trying to call a javaScript function inside href
attribute in html < a >
tag.
In Chrome it's working fine. but in Firefox there is a problem.
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.
use this fiddle example to view it. open it in 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.
Use onclick to trigger functions, you can also use click event using id or class.
<a href="javascript:void(0)" onclick="return test()">Test</a>
using id
<a href="javascript:void(0)" id="clickme">Test</a>
jQuery
$("#clickme").click(function(){
alert("executed");
});
For left, right or middle click you can use mousedown
$(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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.