I am trying to track clicks on an external link (without using a "redirect page").
How can I capture an event when a user follows a link, regardless of whether the user:
The onClick event only applies to the first.
If setting href="javascript:fireEventAndFollowLink()"
the user will not be able to open the link in a new window (2), so this is not a solution.
A link can be triggered in some ways (assuming modern browsers, see foot note):
<a target="_blank">
or <a target="_new">
, the page will be loaded in a new tab.target
values, the link can be loaded in the current screen or another frame.How to capture these links
There is no reliable way to capture all link events.
onmouseup
event can be used to detect 1, 2, and 3.event.button
(or event.which
) property. In all non-IE browsers, 0=Left, 1=Middle, 2=Right. In IE, 1=Left, 2=Middle, 4=Right.onclick
event can be used to capture 1 and 2.event.altKey
and event.shiftKey
properties.oncontextmenu
event can be used to capture 3onkeydown
event can be used to capture 4.The behaviour of the modifier keys is not formalized in any specification, and is thus browser-specific. At least Firefox (at least 3+) and Chrome (all?) implement this key behaviour.
Related question - How to intercept an action on a link (<a>
)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With