admin管理员组

文章数量:1415119

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try 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.

本文标签: javascriptjQueryTriggering Events from Clicking on a Link IssueStack Overflow