I'd like to trigger an event when a link is clicked both by clicking on it normally or by opening it in a new tab (e.g., middle click, ctrl + click, etc)
I've tried the following so far:
$('a').click(myfunc)
Doesn't capture middle clicks.
$('a').mousedown(myfunc)
works, but it seems to be preventing the link from being followed even though my function doesn't call event.preventDefault
.
Any ideas how to do this then?
I'd like to trigger an event when a link is clicked both by clicking on it normally or by opening it in a new tab (e.g., middle click, ctrl + click, etc)
I've tried the following so far:
$('a').click(myfunc)
Doesn't capture middle clicks.
$('a').mousedown(myfunc)
works, but it seems to be preventing the link from being followed even though my function doesn't call event.preventDefault
.
Any ideas how to do this then?
Share Improve this question edited Sep 13, 2015 at 9:29 Kristijan Iliev 4,99710 gold badges30 silver badges51 bronze badges asked Sep 29, 2008 at 1:59 GregGreg 47.2k91 gold badges237 silver badges298 bronze badges1 Answer
Reset to default 6Try returning true from your handler function. Returning nothing can be interpreted by the browser as a void return and thus prevent the default action from being carried out.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745225250a4617429.html
评论列表(0条)