Roger Johansson discusses the
A lot of people got confused and even a little upset when the
target attribute was deprecated in strict doctypes. They saw the decision as arbitrary and limited. In fact, the censure makes perfect sense.
Think about all the style-based attributes that were deprecated. They were dropped because they have no semantic value. They describe how content should be displayed, not what it means. It’s the same with the
target attribute. It describes how a link should behave, not what it is. In that sense, it’s the polar opposite of semantically meaningful attributes like
Now that that’s out of the way…
Suppose you do want to open a link in a new window. What’s the best way of doing it?
You could use a bit of DOM Scripting (
setAttribute) to add a
target attribute, but that’s just passing the buck. You might as well just stick it in your markup to begin with.
It makes more sense to use the
open method of the
window object; the Browser Object Model in other words. You’ll want to do this unobtrusively of course, so you’ll need some way of specifying which links should open in a new window.
A lot of people suggest making use of a
rel="external" declaration in the
a element. The problem with that technique is that it presupposes that the behaviour of activating the link should be defined by whether the link is off-site. In fact, as Richard points out, the most useful examples of opening links in new windows are log-on screens and contextual help. In most situations, neither of those would be off-site. The idea that any off-site link should open in a new window, whether the user likes it or not, harks back to the late-nineties mindset of the internet as a collection of “sticky” walled garden websites.
That said, the class name I chose, “popup”, isn’t very semantically meaningful. It’s not much better than assigning class names like “big” or “red”. If anybody has any better ideas for a class name for the links, I’m all ears.
A nice addition to scripting links to open in new windows would be to make the behavior more obvious. Using a simple bit of DOM Scripting (
appendChild), you could add a piece of text like “[opens in a new window]” to the existing link text.
But DOM Scripting will only get you so far. The real challenge is to figure out if and when you should be opening new windows at all.
In today’s browser world, the
target attribute and the
window.open() method both seem somewhat parochial and old-fashioned. They both presuppose that the user-agent is capable of spawning more than one application window (not true of most mobile devices) and that a whole new window is the only way of having more than one URL open a time. Tabbed browsing put paid to that idea. I wouldn’t be surprised if browser makers began to extend the
window.open() method (perhaps by adding another parameter) to allow the spawning of new tabs.
It could be a whole new world of intrusive advertising: pop-up and pop-under tabs.
Posted by Jeremy on Wednesday, March 29th, 2006 at 12:33pm