Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To target=_blank or not to target=_blank, that is the question!

Should links to external sites set target=_blank? E.g. I am on www.acme.net and have a link to www.otherplace.net, should that link be:

<a href='http://www.otherplace.net' target='_blank'>otherplace's website</a>

or:

<a href='http://www.otherplace.net'>otherplace's website</a>

I was under the impression that using _blank to sites outside your domain was best practice, but now I am being told otherwise.

like image 528
JohnnyBizzle Avatar asked Oct 11 '10 14:10

JohnnyBizzle


People also ask

What is target =_ blank?

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.

Should I use target =_ blank?

The most common reason to use `target=”_blank” is so that offsite links open in a separate tab. This allows a user to click on a reference and come back to it later without leaving the current page. It keeps visitors on your site longer and improves most of your metrics: bounce rate, conversion, pages visited.

Why target =_ blank is deprecated?

If you use target="_blank" only to open links in a new tab, then it is vulnerable to an attacker. When you open a link in a new tab ( target="_blank" ), the page that opens in a new tab can access the initial tab and change its location using the window.

What is the opposite of target _blank?

In short, use target="_blank" it always open a new window but use target="blank" it will open a new window at the first time and this window will be reused after the first.


5 Answers

Some web idealists will state that you should allow the user to make their own choices when it comes to navigation - I have a lot of sympathy with this view. As web developers, we shouldn't be forcing such decisions on our visitors.

However, I also know that businesses often want to 'retain control' and so insist on spawning a new tab/window for external sites. An I understand this too - It's a very practical approach, particularly when you consider that how many users don't know how to control their own UA.

I often tend to steer a middle course between the two, by adding an image (I'm sure you will have seen many in your time) that indicates which links are external, and a note to indicate that external links will open in a new tab/window.

Not quite as 'pure' as the first option, but at least it is clear to the user how the site will behave.

like image 158
CJM Avatar answered Oct 01 '22 10:10

CJM


found this on the w3c site

Checkpoints in this section:

•10.1 Until user agents allow users to turn off spawned windows, do not cause pop-ups or other windows to appear and do not change the current window without informing the user. [Priority 2] Content developers should avoid specifying a new window as the target of a frame with target="_blank".

More info here

the question you need to ask your client is "To what priority level are you aiming to achieve?"

like image 39
Antony Delaney Avatar answered Oct 01 '22 10:10

Antony Delaney


I think it totally depends on your use case.

If you are opening a site in another domain and need to keep your site open, and I think in most cases you do, then use target='_blank'.

As a user, I find it annoying when I click on a link to another domain and it moves me from the original domain. Of course, using ctrl+click in most browsers is a way to defend against this - but why make the user do more work?

like image 37
Mike G Avatar answered Oct 01 '22 10:10

Mike G


It might also be worth to mention that using target attribute is not xhtml valid. I do usually open links in external window or tab because I see that most regular users (not the advanced ones) want it that way so that they can always get back to the site they were on - usually they would go deep into the other site and then it become unfriendly for them having to click back multiple times.

So in terms of usability I think that there's more users that don't use special techniques to manually open links in new window/tab.

With regards to the xhtml validation, you might want to decorate your links with rel="external" or some similar word then use this JS function to handle new window open. I did it like this 99% of time in the last few years.

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}

/**
    DOCUMENT LOAD
**/
$(document).ready(function () {
    /** 
        external links
    **/
    externalLinks();
....
like image 3
mare Avatar answered Oct 01 '22 11:10

mare


Just don't do it. Using target attributes with links presents complications for assistive technology users who may not know another tab has opened. It becomes a bad experience for these users when the back button does not work in the new tab to take them back to the page they started on. This practice can also be disorienting to people with cognitive disorders. It is best to let users decide where links will open.

like image 3
AMG Avatar answered Oct 01 '22 11:10

AMG