I have the following problem: I use Javascript onclick event to change href of a link. It works like a charm but only if user just clicks a link. If "Open in new tab" feature is used for the link - onclick event will not fire and href will never change. Is there any way to handle such an event? Perhaps with jQuery or some other JS Framework?
Example:
<a href="some_url" onclick="this.href = 'some_other_url'">Link</a>
Method 1: Ctrl+Click The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.
You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.
Try to change
<a href="some_url" onclick="this.href = 'some_other_url'">Link</a>
to
<a href="some_url" onmousedown="this.href = 'some_other_url'">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