When to use target="_blank" or onClick="window.open()"?

I have a couple questions regarding the topic in the title of this thread.

Looking at a best practices standpoint, when is it alright or not alright to have a link open in a new window/tab?

Looking at a usability standpoint, when is it alright or not alright to have a link open in a new window/tab?

Usually I open an new window / tab for links that go to an external url (i.e., an URL outside the website domain).
I do this because the website will then still be open, and when the user closes the new window/tab he is back on my website.

Complicated question… firstly, target blank is NEVER a good idea, it’s deprecated code and is outlawed by the W3C. While JavaScript should be used for external links (if you must used them), you need to ensure that it’s unobtrusive and doesn’t require scripting enabled. From a best practice standpoint it’s been stated already that the only time launching content in a new region is considered a worthwhile cause is when it links to external websites (for stuff you have on your website, either link to the other page or hold the data in a lightbox) and for content within a secure page (like if your mid way through paying for something and need to see the terms of service on a separate page. In terms of usability… people don’t like popup’s, in fact they hate them, most browsers automatically cripple them too. If you must use them, use them for launching external sites and secured additional content alone, but the best practice is not to use them unless you need to. :slight_smile:

According to this page (from W3C) _blank is a valid target.

It’s still valid in HTML4 but that’s to be expected as the specification has not updated (now their working on HTML5)… now HTML5 says that it’s valid but emphasises it’s appropriate usage is for being used in conjunction with an iFrame (the target attribute), blank itself still exists however that’s one of the current failings in the HTML5 spec (with it’s blatant disrespect for accessibility). All versions of XHTML prohibit the use of target entirely for the very reasons it’s considered a bad practice.

PS: W3School’s hasn’t been updated in ages, it’s effectively an abandoned site and considered no longer suitable for a reference :stuck_out_tongue:

IMPORTANT: W3Schools is not owned or operated by the W3C. It’s a third party website which has no relation to the World Wide Web Consortium. :slight_smile:

I knew that. It’s not good for a current reference, but the information there is good, if sometimes a bit obsolete. Are you sure it’s been abandoned, or just neglected? (Update: I’ve poked around the site and learned it was maintained by someone called refnesdata.no, who is now quietly advertising the site as for sale. Abandoned seems the proper usage here.)

That I didn’t know. Cheeky of them to present themselves, even implicitly, as an affililate of the W3C (and foolish of me to make the assumption). Their About page is not exactly informative, but as we now know, there’s a reason for that. I did find [URL=“http://www.howphp.com/about/about_refsnes.asp.htm”]this, which is somewhat more illuminating.

Thanks, this certainly answers my question.

Ryan, I might be more interested in such links if they could open sites in new tabs, as opposed to new windows, but as far as I know, there’s no way to do that given current HTML specs and browser configurations. I know that in general, links that open automatically in new windows are considered usability no-nos. And besides, they p!ss me off. :smiley:

Best practice and most accessible is to let your visitors decide. So neither of those options is really needed. All your visitors need do if they want a link to open in a new window or tab is to either configure their browser to do it automatically or to right click and select how they want it to open.

All adding either code does is to remove one or more of their choices.

felgall, doesn’t the typical user not know how to do this though?

Agreed. We advanced users know how to open a link in a new window/tab, but I think average Joe isn’t even aware this is possible.

That doesn’t mean that they should be forced to open a new window though. It is far better that they be educated on how their computer works so that they can choose when they want to open new windows than to have everyone forced to open new windows when asomeone else decides for them.

I totally agree with you, but I can’t help one word springing to mind, sadly as it is: utopia …

As a general rule, you should avoid opening links in new tabs/windows if at all possible. That has been the guidance for years, but with the increasing prevalence of tabbed browsers, it’s more important than ever. Some tabbed browsers open such links in new windows without giving the user the option to open them in new tabs (even though people are more likely to want to open the links in a new tab). Taking that level of control away from the user is not a good plan, because it irritates people, and irritated people don’t make good customers.

Most half-way competent surfers know they can right-click and “Open in new tab/window”, and can choose to do this as and when they want to open the link in a new tab or window. If they aren’t that clued up, the chances are they are likely to get confused by clicking on a link and then not being able to go back to the previous page.

The only time that you should open links in a new tab/window is when it would be damaging for people to navigate away from a page and then use the back button - eg a form or interactive feature that might lose any inputs the user has already made.

(Only the ~1% of surfers who are smart enough to use Opera can choose to override the page and open a link in the current tab/window even if the code says it should open in a new one - hurrah for Opera!)

Best practices and usability will give you the same answer - things are considered to be best practices because they work best for people using your site, not for any other reason.

You can do it in Firefox as well provided that you install the appropriate extension and configure it correctly.

IMO the deciding factor is whether you wish your visitor to usefully stay with a tab/window open on the prime site - while diverting to the new link. It is amazing (seemingly) how few folks seem to know how to use their back button etc.

A good example can be - a page with a selection of external links - and you want visitors to be able to go thru the list one at a time perhaps - thus by keeping their original tab/window available they do not have to keep back buttoning. If more folks used and knew about “open new window/tab” there would not be a problem.

The ‘target’ attribute (when applied to an anchor) can be used in any (x)html Transitional document and typically is supposed to be associated with a Frameset hence why is has never been deprecated for Transitional documents.

Essentially the TARGET attribute is used with frames to specify in which frame the link should be rendered obviously you can have target on more elements than the anchor; _blank renders the link in a new, unnamed window.

Though obviously you are supposed to use scripts if you want to spawn a new window not related to a frame and that is why Strict doesn’t use it.

The HTML 3.2 tags that were deleted from HTML 4 are the ones that are in the transitional doctype and labelled as deprecated. Those are the ones that you are supposed to be replacing as you transition from using HTML 3.2 to using HTML 4. Once you finish transitioning to HTML 4 you can then use the HTML 4 strict doctype.

And from reading the spec they have added it back into HTML5 (not only that their using target to justify the Iframe element for “sandboxing”) bad move IMO. :frowning:

The Frameset didn’t even occur in HTML 3.2 and as for HTML 4.01 the ‘target’ is not Deprecated or it would have been listed as such because you cannot even have ‘target’ on an HTML 3.2 Anchor in the first place.

Though I know what you are getting at; APPLET, BASEFONT, CENTER, DIR, FONT, ISINDEX, MENU, S, STRIKE, and U (all deprecated). I agree in the sense that is the objective though.