views:

144

answers:

5

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.

+1  A: 

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?

MikeG
+1  A: 

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.

aaronmase
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.
JohnnyBizzle
Is there a code of conduct for governmental websites?
aaronmase
@aaronmase: Your government or my government?
CJM
UK Government in my case (National Health Service)
JohnnyBizzle
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.
mare
@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.
CJM
+1  A: 

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();
....
mare
Can you not tell from the href attribute value alone whether a link is external or not? Wouldn't that be more reliable?
Alohci
I was looking at a similar question before posting this http://stackoverflow.com/questions/2420664/how-to-w3c-validate-a-target-blank
JohnnyBizzle
well then, what is your question exactly?
mare
@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.
mare
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.
CJM
Note: target attribute is NOT depracated in HTML5 according to this: http://dev.w3.org/html5/spec/Overview.html#the-a-element
CJM
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.
mare
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.01
CJM
+2  A: 

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

Antony Delaney
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 spec
Pekka
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.
Antony Delaney
+2  A: 

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.

CJM
+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.
Roger Pate
Added an image and text next to the link: (links open in new window)
JohnnyBizzle