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

8

30

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.

Marjorie answered 11/10, 2010 at 14:0 Comment(13)
Who is telling you otherwise and with what arguments?Kentonkentucky
One argument I have heard against it is that it takes a measure of control away from the user, and that it's better to let the user decide whether their links are going to open in a new window/tab or not.Deberadeberry
i think the only reason it would be "best practice" is that if you dont use _blank for an external website then you are taking someone away from your site - whereas if it were _blank then you are keeping the user on your site - not specifically "best practice" id sayGeometer
I'm being told it's not within accessibility guidelines to open in a new window. As it is a government website, it needs to be accessible.Marjorie
Opening new windows is one of Jakob Nielsen's Top 10 Mistakes in web design (useit.com/alertbox/9605.html), but I admit he's not universally popular...Eggert
yes, all the websites in the world should look like Nielsen's website, that would make the web such a lovely place, sarcastic.;)Olenta
@Phil Nielsen often has a point, but for external links, opening a new window is simply self-defense - countless users do not know how to navigate back to the original siteKentonkentucky
@Kentonkentucky I agree - this seems like a valid use of _blank, just thought i'd throw his arguments into the mix as they're always good for discussion :)Eggert
@Phil yeah. It's not like he's not right with many things he says. He just tends to be a bit... fundamental sometimes :)Kentonkentucky
Nielsen does a good job of 'keeping us honest'. You don't have to adhere to every proclamation he makes, as long as you understand what he is saying and factor it into your work. And 'fundamental' is probably a good adjective, I think.Declamation
@Pekka: "Countless" users get confused when you break the back button and the old window gets lost in the background.Mechanize
@Declamation I would agree with that, nicely put. @Roger true, neither approach is perfect. But unexperienced users not finding back to the original site really are a huge issue.Kentonkentucky
I don't think it is best practice. It takes control away from the user, breaks the back button, and can come across as spammy and self-promotional, like the webmaster cares more about keeping users on their own site than creating a good user experience. I use _blank only when I have a compelling reason, like links that open an explanation page about how to fill out a form.Soper
D
19

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.

Declamation answered 11/10, 2010 at 15:3 Comment(2)
+1 for the very important point of making it clear to the user how the site will behave. The type of users who can't find the back button (which is often prominent and in a prime location...) are just as liable to be more confused by some links "randomly" opening in a new window and some not.Mechanize
Added an image and text next to the link: (links open in new window)Marjorie
G
12

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?"

Geranium answered 11/10, 2010 at 14:31 Comment(2)
Those are the Content Accessibility Guidelines though. A valuable resource, and a must when building accessible web sites. But it's not a binding general standard like the HTML specKentonkentucky
JohnnyBizzle said "I'm being told it's not within accessibility guidelines to open in a new window". So a good place to look would be the Accessibility Guideline, to see if what he has been told is correct.Geranium
H
4

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?

Hypnoanalysis answered 11/10, 2010 at 14:8 Comment(2)
Sorry, but that's just wrong. You don't want the user to have more work; that's okay. But I personally hate it, when websites open new windows. In this case, I have NO OPTION whether the page should open in a new window, a new tab or the same tab. It just opens. If you don't use target='_blank', the user can decide if the page should open in the same tab (click), in another tab (ctrl+click/right click 'open in new tab' or in a new window ('right click 'open in new window').Favrot
Like I said, it's context-sensitive. Sorry but you can't say I'm wrong based on your personal opinion. That being said, after a year straight of mulling over this issue - I do agree that it is nice to give the user control over how links works :-).Hypnoanalysis
O
3

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();
....
Olenta answered 11/10, 2010 at 14:25 Comment(8)
Can you not tell from the href attribute value alone whether a link is external or not? Wouldn't that be more reliable?Tenenbaum
I was looking at a similar question before posting this #2421164Marjorie
well then, what is your question exactly?Olenta
@alohci: external is just a word I put in rel to identify those links that JS code should pick up. External does not mean external site, it means external (or new) window.Olenta
Talk about the tail wagging the dog. Validation is useful, but is only a means to an end. You've added some unnecessary javascript to con a validator that you are rendering valid xhtml. A better solution would be to a) not use the target attribute, b) use HMTL(5) or c) simply accept that your site is 99% 'valid' and works fine without tinkering.Declamation
Note: target attribute is NOT depracated in HTML5 according to this: dev.w3.org/html5/spec/Overview.html#the-a-elementDeclamation
Personally I always liked the target attribute. But I also like to have my sites validated. For me, validation is a baseline to which I like to adhere when releasing the site online. To cut through both these two requirements people invented this JS technique and it works fine. If someone doesn't want to use it, it's fine with me too. With regards to HTML5, I think not everyone is ready to start developing with HTML5 - that kind of switch requires time and money.Olenta
I use validation as a baseline too. I validate, and if I find one or two breaches on a page that I can specifically explained away (e.g. target attribute), I regard myself as satisfied. PS - still nothing wrong with HTML4.01Declamation
H
3

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.

Hampson answered 18/6, 2015 at 23:8 Comment(0)
U
2

You need to predict what your users want. Use target="_blank" if you expect your users will want to stay on the site.

For example if a blog post has a link in the middle of the post, it makes sense to open that link in a new tab since you are expecting the reader to return to the page and continue reading.

Some people argue that the reader could simply click "Back" when they wanted to come back to the page,

But new webpages will have more links to webpages that have more links, what happens is that the reader has to "Back" a couple of times to get back to your blog post. Either that, or he ends up "lost" in the myriad of linked pages and couldn't come back to your blogpost (you can be sure that no one wants to open History and find your page again when they are "lost", unless there is a big incentive to coming back to your page).

Upthrust answered 1/1, 2012 at 13:35 Comment(0)
H
1

As it is a governmental website, this is a tricky question. I regularly see disclaimers for external sites on these type of sites. I don't know if this is a standard or not.

I think the answer is probably down to your own opinion, which should probably be based on usability and integrity.

Harri answered 11/10, 2010 at 14:16 Comment(5)
Exactly! Is it clear to the user that they are on another site, not necessariliy created or the content provided by you? But on the other hand, it is easy for a user to r-click, open in new window if they want.Marjorie
@aaronmase: Your government or my government?Declamation
UK Government in my case (National Health Service)Marjorie
With my solution (or Nick Craver's for that matter) you can easily wire up message box (alert window) telling the visitor that he's leaving the current site.Olenta
@Johnny - my point was that this is a multi-national site and there are no 'code of conduct for governmental websites' that cover us all.Declamation
S
1

Just make two buttons for your users: One to open in new tab, and another to abandon the current page in favor of the linked page.

[ www.google.com ] [Open Google in place of THIS page]

Sheave answered 6/5, 2013 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.