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?
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.
A target attribute with the value of “_blank” opens the linked document in a new window or tab.
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.
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.
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"
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