Daily Dish of Dominey Design
{  May 2, 2003  }

Standards Compliant "_blank" Windows

One of the often-heard complaints among web developers who migrate their HTML 4.0 or XHTML 1.0 Transitional content to XHTML 1.0 Strict is that the anchor tag property "target" no longer exists. Which, in turn, means that designers striving for complete document validity can no longer pop-open a user's window when linking to off-site content.

Ever since I updated this site to the Strict doctype, I have received numerous emails from readers asking why the "Enjoying" side bar links don't open in new windows. Over and over, I have replied that it is was "impossible" to implement without breaking the site's validity. Well, I was wrong.

Thanks to a link from reader Paul Livingstone, I have implemented the javascript workaround detailed by Kevin Yank in his article "New Window Links in a Standards Compliant World". By modifying the "rel" property of the anchor tag - which is perfectly legit under XHTML - you can create links with targets and still maintain document validity.

So now comes the obvious question - is this cheating?

The answer is no. The Document Object Model (DOM), which governs the document objects and attributes that are available to JavaScript code, is a totally separate standard from (X)HTML. Also consider that the DOM 2.0 standard that was published in January 2003 (well after XHTML 1.0, let alone HTML 4.0) still includes this attribute. It seems clear that while this attribute is slated to be phased out of (X)HTML, it will be available to JavaScript through the DOM for the foreseeable future.

Some may take issue with Yank's opinion, but to me it makes sense. And the benefits of serving the user while maintaining document validity - however it is accomplished - is more important than obsessing over specifications of which I have zero control.

Comments

I will just throw in my opinion on the use of target=_blank here, I would love to hear other people's take on it.

When I browse sites (using Phoenix which supports tabbed browsing) I want to be in total control. I usually browse several sites at once using the same browser window, opening all interesting links in tabs along the way. It happens often however that I'm done with a particular page and want to follow a link from it to another site and so I click it and it opens a new window...

That means that I have to alt-tab back (I'm Windows, sorry ;)) and close the old window. If I still have other tabs open in the old window I instead have to close the new window and then open the link in a new tab and close the originating tab to get rid of it.

It's nothing but a hazzle to me.

If people want to open a link in a new windows they can use the dropdown menu or shift-click on it (this is Windows specific, I'm sure there's an OS X equivalent to it as well). That way everyone's happy.

Anything that tampers with my browser is baaaad per definition.

My $0.2.

Posted by: Michael at May 2, 2003 11:12 AM

...and that's the rub of the situation Michael. That some users prefer the simple click-and-open approach without having to put their hands on the keyboard, and keep the "parent" site live on their screen to they can go back. Others prefer sites that don't stipulate what happens with their browser. I perfectly understand both sides of the situation. And truth is, I'm not sure what the answer is.

Posted by: Todd Dominey at May 2, 2003 11:20 AM

I’m not really familiar with Phoenix, however in regards to ‘Tabbed’ browsing… in Netscape (my only experience with tabbed browsing) you can control whether a link launches as a new window or a tab regardless of the html (or in this case XHTML) code.

So.. with the new and improved ‘enjoying’ section (IMHO) i can single click, and get a new window… or I can middle click to launch in a tab. That’s hardly tampering with a browser… is it?

Posted by: Paul Livingstone at May 2, 2003 11:27 AM

Frankly, I can't understand why anyone wanted link to open a new window. It takes choice away. When I'm browsing and clicking on a link, I want one of four things to happen:

1) Open the Link in the current window if I don't want to see anything else on that page
2) Open the Link in a new tab if it's somehow semantically connected to the active page, but I'm not done reading it anymore
3) Open the Link in a new window behind the active window if I want to read the content later
4) Open the Link in front of the currently active window if I want to quickly read something and then close it again to go back to where I came from

Automatically opening links in new windows takes this choice away from me, and it does so in a way that I can't predict. All links look the same, so I expect them to behave the same. There's no rule for how links that open in new windows should look like, so it's confusing that links behave differently.

Furthermore, I have noticed that there are two classes of users:
1) "Power Browsers" who know that they can open a link in a new window manually if they want to
2) "Casual Browsers" who *don't* know it and get confused if new windows open by themselves. Sometimes they don't even notice that they're in a new window and have no idea why "back stopped working". They often don't know how to get back to the page that opened the new window.

Therefore, I would stay away from links who open new windows whenever possible.

Posted by: LKM at May 2, 2003 11:38 AM

I know when I visit a site, I don't care what sidebar links do. If they take over the current browser window, fine. If I want control of where they go, I'll right-click or option-click and do a new window or tab. However when I'm reading something like a blog where there are links mixed into the blog, I want them in separate windows, so that I can check out the link and continue reading the blog. This is a personal preference though, so I don't know if it should be forced down the readers throats, however why would I want to send someone away from my site either?

Posted by: Chris at May 2, 2003 11:50 AM

Umm, now I like the idea of external links being opened in a new window (well if it's good enough for Jeffrey Zeldman then it's good enough for me!).

In fact on my own site (http://www.springworks.co.uk/) I have used this approach, in a valid XHTML 1.0 Strict environment I might add, using a far simpler method than that suggested.

How? By simply using JavaScript onClick event handlers to open a new window within each link tag.

Now I may just be naive, but my pages validate and the links work, so why doesn't everybody else adopt this approach? (Or have I missed some basic problem - if so, please enlighten me!)

Posted by: Steve Rowling at May 2, 2003 11:58 AM

Personally, I hate sites that open links in a new window. It’s only gotten worse since I’ve become addicted to tabbed browsing, and now I wish there were a way to make all attempts to open links in a new window instead open in a tab.

Barring this, I’m giddy with the information found here that lets Mozilla-based browsers force links to open in the current window. And yes, it defeats this sites attempts as well.=-)

Posted by: Jemaleddin Cole at May 2, 2003 12:39 PM

>however why would I want to
>send someone away from my
>site either?

You aren't sending them away. They decide to go to another site. The web developer should respect this decision, because if he doesn't, if he tries to lock people in, they won't come back.

In the end, you lose people by trying to keep them.

Posted by: LKM at May 2, 2003 12:40 PM

I agree that having control when browsing the web is preferred, but popping a link target into its own, named window is sometimes necessary -- mostly when dealing with web-based applications, content management systems or other tools.

It's stuff like throwing out "target" that keep me away from Strict, unfortunately. It's such a far simpler method than using JavaScript. Isn't it?

Posted by: Dan at May 2, 2003 1:07 PM

Surely this method of 'adding' the target attribute to the A tags invalidates the code. The only reason that it still validates is because the validator doesn't run the JavaScript, once this happens it's invalid. Just because it's in the DOM doesn't mean that it's in XHTML. Forgive me if I'm wrong but that's the way I see it.
Like Steve says above, the best way of making a link load in a new window is the onClick event. You could even add this dynamically in the same way that you add the target attribute.

Posted by: Ric at May 2, 2003 1:09 PM

I'm curious--why did the XHTML working group decide to eliminate 'target'? It's a perfectly logical attribute IMHO. I use it frequently on my client access site to pop up new windows to show designs, without leaving the project page.
Mostly, I use it when I'm too lazy to write a real JS popup. Still, I think it has its place.
The JS method for walking the DOM to set the target is nice, but does smack of 'cheating' because it relies on JS instead of just marked up code. Oh, well, what's a site w/o javascript these days?

Posted by: R. A. White at May 2, 2003 1:10 PM

Are frames still a part of XHTML 1.0 Strict? If so how do you target them individually without target?

Posted by: Michael at May 2, 2003 1:30 PM

Ric, I'm pretty sure the explanation quoted in Todd's post holds up. The most up-to-date recommendation for the DOM (2) includes target, and from another part of the spec: "This section... describe[s] objects and methods specific to HTML documents [HTML 4.01], and XHTML documents [XHTML 1.0]." Taken together, it would seem that this is completely kosher for use with XHTML.

Posted by: Nate at May 2, 2003 1:31 PM

Why mess with the target attribute at all? What's wrong with onclick="window.open(this.href);return false"? Don't even need the DOM for that.

Posted by: Dave at May 2, 2003 1:37 PM

I have just redesigned my site using XHTML 1.0 Strict and opened it up today and had toyed with the idea of using a JavaScript to open new browser windows on my sidebar links but chose not to have links open in new windows because hey, the users do have a back button and should they wish to return they can do.

Posted by: Paul at May 2, 2003 1:50 PM

I have just redesigned my site using XHTML 1.0 Strict and opened it up today and had toyed with the idea of using a JavaScript to open new browser windows on my sidebar links but chose not to have links open in new windows because hey, the users do have a back button and should they wish to return they can do.

Posted by: Paul at May 2, 2003 1:50 PM

Damn. Sorry for the double post, not sure why it has done that ?

Posted by: Paul at May 2, 2003 1:51 PM

I agree with LKM wholeheartedly.

To quote the man everone loves to hate:

Opening up new browser windows is like a vacuum cleaner sales person who starts a visit by emptying an ash tray on the customer's carpet. Don't pollute my screen with any more windows, thanks (particularly since current operating systems have miserable window management). If I want a new window, I will open it myself!

Designers open new browser windows on the theory that it keeps users on their site. But even disregarding the user-hostile message implied in taking over the user's machine, the strategy is self-defeating since it disables the Back button which is the normal way users return to previous sites. Users often don't notice that a new window has opened, especially if they are using a small monitor where the windows are maximized to fill up the screen. So a user who tries to return to the origin will be confused by a grayed out Back button.

Posted by: ss at May 2, 2003 2:13 PM

This is good to know - The "target" issue is what was keeping me from deploying in XHTML 1.0 Strict. However annoying the fact that opening new browser windows might be to some, there are some instances where they are useful - as in exploring new content or carrying on a reservation process for a hotel -recent case here- while continuing to explore the remainder of the site for further information. Also, a "control" popup window might open links on its parent window using window.opener.location via javascript... clients often request things like these.

However, if browser tabs were scriptable in a standards-compliant way, I'd be more than happy using them instead of opening new dreadful windows. Just waiting for IE to catch up...

Posted by: beto at May 2, 2003 2:17 PM

While I do think opening a new window can be useful (I happen to like these small comment windows :)), I personally preach the path of not using it unless absolutely necessary.

From the same link posted by ss:

"Interaction consistency is an additional reason it's wrong to open new browser windows: the standard result of clicking a link is that the destination page replaces the origination page in the same browser window. Anything else is a violation of the users' expectations and makes them feel insecure in their mastery of the Web."

Please stay away from interacting with my browser in any ways not sanctioned by me ;)

Posted by: Michael at May 2, 2003 2:58 PM

If a user is confused by a grayed out back button, then they need to learn how to use the web. Period.

Hey, I understand that we need standards and validation, etc...but c'mon. How long are we going to read about web-safe colors, 640x480 browser windows and supporting Netscape 2.0 and all the other crap that we constantly hear about?

It's time to move on...

Posted by: Paul V at May 2, 2003 2:59 PM

Opening new windows for “external” links is wrong wrong wrong.

1. it causes desktop clutter
2. breaks back button
3. takes control away from the user
4. annoys power users (there is no “open link in SAME window command because this should always be the DEFAULT behavior)
5. ultimately, its just plain rude: “my blog is so awesome that it must remain open in the background in case you had any thoughts about going elsewhere!”

anyway, browser makers like netscape are putting control of window behavior back in users’ hands, so trying to control how links are followed is becoming an exercise in futility.

Posted by: nathan at May 2, 2003 3:13 PM

I like the small comment windows such as this one, but I don't link that the next window that I open will inherit it's size. Phoooey.

Posted by: Mr. Kotter at May 2, 2003 4:14 PM

While I believe that MOST new windows are bad for reasons already stated, my rule of thumb is that if a link is a certain dead-end (e.g., a small explanation pop-up page with no further links of its own), it may justify opening up in a new window so users can read it, close it and continue with the task at hand. That goes for these comment pop-ups as well as "what's this?" type links.

Posted by: ss at May 2, 2003 7:04 PM

Yet another example of a complicated workaround to achieve something that used to be so simple, just for the benefit of oblique, half-implemented standards that don't work half the time. Yay!

People, web building shouldn't be a religion. Use the code that works.

Also, to my eyes, when a site opens links in a new browser, it just makes them look insecure. Oh, please don't go! The web is a hypertext medium - deal with it.

(As an aside, I'm not usually this grumpy. And it's your site, so you should do whatever you want. I blame the rain.)

Posted by: Derek at May 2, 2003 7:37 PM

I've found that power users nearly always have trouble believing that the "non-working back button" is an issue.

Generally, if you're using a 21" monitor, and know that there's any such thing as a "target" attribute, you know too much to understand the mindset that contributes to the confusion.

If you watch people tripped up by this again and again, it eventually clicks.

The only situation where it's okay to open a new window is when the new window benefits from special formatting (size, position, stripping away browser chrome) like this window—for presenting meta information.

If you don't need that kind of formatting control, leave the link target alone. The user can open a new window if they want to. If they don't know how, then they'll likely fall into the group that would have been confused by the new window anyway.

Posted by: jeff at May 2, 2003 11:08 PM

I agree with the majority of you that opening links in a new window is a fair usability flaw. I wouldn't say that it's always a horrible thing (e.g. I actually like that the Enjoying links on this site open in a new window ), but as a general rule, we should try to stay away from it.

I think the W3C was completely in the right, though, in taking the target attribute out of XHTML 1.0 Strict. It really doesn't have any structural significance, which is the intention of HTML in the first place, and was meant originally (if I'm not mistaken) exclusively for framesets. If we've gotten rid of framesets (we have, thankfully) then there's no reason to still have the target attribute.

Personally, I love the method the article proposes. Using the rel attribute provides incredibly relevant semantic information (whereas target="_blank" provides nothing), and the browser, whose job this really is, ends up carrying the load. Target has no place in a pure HTML; JavaScript should rightfully take this task as its own.

Posted by: Brian Hamilton at May 3, 2003 1:04 AM

in ie on the pc, you can drag any link to the browser chrome ( your wonderful grey bevelly parts ) and that will open the href part of the anchor in that window, regardless of what a target, onclick, or whatnot is trying to do to you.

most other browsers require you to drag the link out of the browser and then back into the browser and release.

i thought people knew that. i guess not.

Posted by: james at May 3, 2003 1:39 AM

What does that have to do with target=_blank? Half of us probably aren't even on IE. I'm on Phoenix for instance.

Posted by: Michael at May 3, 2003 4:57 AM

>If a user is confused by a grayed
>out back button, then they need
>to learn how to use the web.

Well, maybe, but if they *do* learn how to use the web, then they do also know how to open a link in a new window if they want to.

Posted by: LKM at May 3, 2003 6:37 AM

michael, because someone was saying that you can't open a link in the same window, if target is defined.

also, to answer your previous question about frames. strict doesn't allow frames, so you'd have to declare it as a frameset and then target is a valid attribute.

Posted by: james at May 3, 2003 12:21 PM

"All links look the same, so I expect them to behave the same. "

at least one browser recognised that problem: iCab for the mac would subtly change the cursor when pointing at a link with a target attribute ... normal links get the finger pointing hand, popup links get the finger pointing hand with a small blank document icon infixed.

After seeing that only once or twice i was no longer suprised by popup windows. I knew they were coming, just by pointing at the link.

Of course, if I open the links by other than pointing with the mouse cursor, I was none the wiser. And whether it was a good thing or not that it was a popup is a different question.

Bottom line though: through a very simple change in interation behaviour I was able to predict the consequences of my actions. That's one part of the definition of being in control.

Posted by: Eric Scheid at May 4, 2003 12:21 AM

That is a pretty good way to handle the presence of _blank, though as you also say it doesn't justify their presence :)

Posted by: Michael at May 4, 2003 5:23 AM

I don't understand how you can all use phoenix to develope with when your average mom and pop joe user is not.

I always use and develope with the most used browser, no matter what it may be, and of course test in the others.

Posted by: brandy at May 4, 2003 10:52 AM

I do it the other way around.

Posted by: Michael at May 4, 2003 11:41 AM

hehe what about when flash opens a new window, and you can't right click in it either (currently).

Posted by: brandy at May 4, 2003 8:16 PM

I personally think that opening a new window is evil. Despite good intentions, you do usurp control of the browser, something that should not be done.

In all reality, (x)HTML and CSS really give the ‘best suggestion’ of what a site should look like to the browser, and then the user’s browser renders the page using it’s rules. Browser’s interpretations vary, it happens.

It’s a fundamental difference in web design approach. Do you provide your content, and let the user decide how to interpret that data and how to use it based on their browser, or do you force how data is presented with javascript browser detection, hacks, forced new windows, etc..? This is a major issue with accessability.

So which way is better? I don’t think there is any ‘best’ way. I prefer the ‘offering the best suggestion’ approach, primarily because of accessability concerns (education institution). It all depends.

Sorry if this is a bit long winded!

Posted by: Sean Sieg at May 4, 2003 10:11 PM

"Also, to my eyes, when a site opens links in a new browser, it just makes them look insecure. Oh, please don?t go! The web is a hypertext medium - deal with it."

I've always seen it this way - very satisfying to see at least one other person using the very words that I would use.

The worst thing damage that named targets do to navigation is this: if I want to open two external links in two different new windows I can't, for example on Zeldman's site. Since his links all open in the same named target, the second click will overwrite the first. I tend to avoid sites that display this kind of rudeness.

Posted by: Lee Phillips at May 4, 2003 10:47 PM

"The answer is no. The Document Object Model (DOM), which governs the document objects and attributes that are available to JavaScript code, is a totally separate standard from (X)HTML."

Actually - the answer is "yes".

Or to quote the DOM specification (http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html.html): " For DOM Level 1, the transitional and frameset DTDs for HTML 4.0 are assumed. Interoperability between implementations is only guaranteed for elements and attributes that are specified in these DTDs."

Posted by: David Dorward at May 5, 2003 10:06 AM

In my mind, the TARGET tag is analog to the FONT tag in that, if tomorrow your boss asks you to change the properties of external links (or the color of your text), it would require you to replace every single occurence of the attribute that exists on a site. Whereas, using Tod's method you only need to change a single script. That's much closer to the CSS method of using a single style document to govern an entire site, which suits me better.

Aside from all of the usability rationales, which also sound sensible.

Posted by: Micah at May 5, 2003 3:35 PM

Happy Birthday! :)

Posted by: Ruthie at May 6, 2003 12:57 AM

New windows should only be used if it is within the site, and is only temporary, like forms, comments, product descriptions, etc.

New windows for external sites are annoying as hell. If I want a new window (because I want to come back usually) I will open it.

This should be common knowledge, new windows for external sites is just a bad design, like using dark blue text on a black background. DUH!

Posted by: Lonnie at May 11, 2003 12:50 PM

archives

You are reading "Standards Compliant "_blank" Windows" in the individual archives.

Check out other recent posts in the Tech, Web category

Return to the front page.