Difference in Chrome between `target="_blank"` and Right Click + `Open Link in New Tab`

Viewed 482

Suppose I have a link to Google of the form

<a href="https://www.google.com" target="_blank">Google</a>

There are a couple different ways to open this link in a new tab:

  1. Left click on the link
  2. Right click on the link and select Open Link in New Tab

I've noticed on an app I work on that there is different behavior between #1 and #2. For example, when I console out window.opener for #1 I get an object like

window.opener left clicking on a link with target="_blank"

wheres #2 gives me undefined.

What are the differences between these two ways to open the link? I can't find any information about how a browser (in my case, Chrome), might handle these cases.

1 Answers

I had the same problem, two different behaviors were happening in those two cases in an application I was working on. I had to search everywhere to see why, only to find your question that helped me identify the problem.

in case #1, of course when you left click the link, the user is giving the developer the choice of whither to open in a new tab. whereas in case #2, the user is making the choice instead.

case #1 is like doing window.open(URL, '_blank'); case #2 is like opening a new tab and manually typing the URL;

the only thing I found is that when you open the URL with target blank (case #1), that new tab or window will link to the parent (opener) by window.opener until you close that window, the opener will be back to null

as far as behavior, the source code of the new URL may include logic on window.opener you may need to search if this was the case. I don't see why the browser would treat them differently, it has to be from the source code.

Related