Javascript event for "Open in new tab"

I have the following problem: I use Javascript onclick to change the href of the link. It works like a charm, but only if the user simply clicks the link. If the link uses the "Open in a new tab" function, the onclick event will not fire, and href will never change. Is there any way to deal with such an event? Perhaps with jQuery or another JS Framework?

Example:

<a href="some_url" onclick="this.href = 'some_other_url'">Link</a> 

Many thanks!

+6
source share
1 answer

Try to change

 <a href="some_url" onclick="this.href = 'some_other_url'">Link</a> 

for

 <a href="some_url" onmousedown="this.href = 'some_other_url'">Link</a> 
+9
source

Source: https://habr.com/ru/post/925101/


All Articles