Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Event for "Open in new Tab"

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>
like image 522
Jacek Francuz Avatar asked Sep 11 '12 08:09

Jacek Francuz


People also ask

How do I make a link open in a new tab?

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.

How do I make a link open in a new tab in HTML?

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.


1 Answers

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>
like image 51
Mateusz Rogulski Avatar answered Oct 25 '22 11:10

Mateusz Rogulski