michael orlitzky

Avoid the link “target” attribute


If you've ever clicked on a link and had it surprise you by opening a new window, you were the victim of target="_blank". Web designers often try to force links to open in new windows out of an irrational fear: that you're the stupidest person alive, and if you follow a link, you won't know what happened or how to get back to their site (which is where you really want to be, right?).

This is obnoxious and a bad idea besides—it has been for years—but somehow it still comes up. Here's why yo.

It's Non-standard

The target attribute has never existed in (strict) HTML 4, XHTML 1.0, or XHTML 1.1. If you use it, your page is invalid.

This matters if you care about things like Section 508 compliance; the Web Content Accessibility Guidelines state that you should create documents that validate to published formal grammars. (Yes, that reference is for WCAG 1.0. WCAG 2.0 says more or less the same thing.)

It's Redundant

If the user wants to open your link in a new window or tab, he can right click it and choose “Open Link in New Window” or “Open Link in New Tab”. There are hotkeys (e.g. Ctrl-left-click) to make this more convenient.

It's Presumptuous

The idea that you can force a “New Window” to open supposes that the user is reading the site via your idea of a web browser. This may not be the case.

Many vision-impaired users access the web with a screen reader (software that reads the webpage aloud). If a computerized voice is reading the webpage to you, what does it mean to “open a new window”?

(This is why the attribute is not part of XHTML).

It's Annoying

Ten years ago, a pop-up blocker was all but required when browsing the web. Every website took it upon itself to open hundreds of little pop-up windows. They were annoying and made it hard to do anything; thus, pop-up blockers were invented. The popularity of pop-up blockers is a testament to how annoying the pop-ups were. Guess what? They're still annoying.

It Breaks the Back Button

You don't need to trick your visitors into remaining on your site. Since prehistory, there has been a button that allows you to go back to the page you were just on. It is cryptically designated the “Back” button. People know what it does, trust me.

If you force a new window to open when the user clicks a link, the back button on that new window will be grayed out. So when your user tries to use the “Back” button to go “Back” to your site, it won't work.

It Messes with Google Analytics

Google Analytics (among others) tracks how long each visitor remained on a particular page. If Google Analytics tells you that visitors spend an average of 15 minutes reading dildos.html, then maybe your customers really love dildos. Or, maybe they were reading a PDF that you forced to open in another window during that time.

The Google Analytics script can't tell where the user's eyes are pointing, so it treats these two scenarios the same. You can't tell which happened, so the numbers become less meaningful.

It Doesn't Play Well with PDFs

This should really be, “it doesn't play well with any file format that has a widespread browser-plugin”. But PDFs are the main issue, since many people use the Adobe Reader plugin to read PDFs within their web browser.

As a user: I agree, you often don't want a PDF to open on top of the website you're browsing. But using target="_blank" on all PDF links is the wrong way to accomplish this, because the users who don't have the browser plugin will see strange behavior.

First, a new blank window or tab opens with the address bar set to the URL of the PDF. Then, the PDF file downloads and opens in a separate program (the PDF reader). This is all according to plan. But when the PDF reader is closed or minimized, focus returns to the web browser, which was left viewing a blank page! Oh, and the back button doesn't work.

The best solution here is to eliminate PDF reader plugins from the browsers entirely; they serve no purpose except to crash your web browser if/when the PDF reader crashes. Without browser plugins, the correct thing would already happen for everyone, so you wouldn't need to fuck around with new windows/tabs.

It Doesn't Play Well with Tabs that Open in the Background

This one is self-explanatory. If the user has his browser configured to open tabs in the background, he might think that nothing happened when he clicked your link.

It's not his fault if he doesn't notice the new tab that opened in the background; after all, a new tab should only be opened when he Ctrl-left-clicks or chooses “Open in New Tab”.