Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target="_blank" vs window.open

I'm working on an application where users enter some input and they shouldn't leave the page when clicking on share links, e.g. a Facebook share link:

<a href="https://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.example.com%2F">Share on Facebook</a>

I know it's very common to use popup windows for such links. But does it have any advantage over a simple target="_blank" attribute? How do you compare the two methods and which is the right practice in such cases?

like image 451
Mori Avatar asked Jun 30 '14 17:06

Mori


People also ask

Should you use target _blank?

The target=”_blank” link attribute is risky and opens a website to security and performance issues. Google's Web. dev page on the risks of using the _blank link attribute is summarized as such: “The other page may run on the same process as your page.

What does a target _blank mean?

A target attribute with the value of “_blank” opens the linked document in a new window or tab.

What is _blank for window open?

a target=”_blank” Open in New Browser Tab (or Window) The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.

What is the difference between target blank and target _blank?

The difference: target="_blank" is a special keyword that will open links in a new tab every time. target="blank" will open the first-clicked link in a new tab, but any future links that share target="blank" will open in that same newly-opened tab.


1 Answers

It depends what HTML version you use and if you care about W3C validation. In HTML5 you can use target="_blank" but with previous XHTML versions you couldn't and you had to use JavaScript to achieve the same result and make your site W3C valid. I think that's the only reason why many people used this method.

Of course using Javascript makes that user has to have JavaScript enabled to open this link in new window (and using adblocks/ghostery and similar addons make block some JavaScript) so I think if you only can, you should use target="_blank"

like image 82
Marcin Nabiałek Avatar answered Oct 03 '22 16:10

Marcin Nabiałek