XHTML 1.1 Second Edition with Target Attribute
When I switched from HTML 4 to XHTML 1.1 a couple of years ago, I soon found the target
attribute was missing. I have never been in love with the target
attribute anyway, but some clients insisted that their links should open in a new window. So I did some research.
You won’t believe how much myth and misinformation is out there. Some say it’s deprecated. In fact it never was. It is part of XHTML 2 and XHTML Basic, and there is a target
module in XHTML 1.1, the modularized version of XHTML. The attribute is not included in HTML 4.01 Strict and XHTML 1.0 Strict because it was then considered to be related to frame
s and iframe
s, but it’s not marked “deprecated.” It was simply not in the core set of modules for the XHTML 1.1 driver.
Some people argued it’s a behavior and thus belongs into unobtrusive JavaScript. But then clicking on a link to get to another page is also some functionality, and nobody would think of replacing anchors with loads of bloated script to simulate such a basic behavior.
So I ended up extending the extensible with a customized DTD:
<?xml version="1.0" encoding="iso-8859-1"?>
- <!-- Bring in the XHTML 1.1 driver -->
<!ENTITY % xhtml11.dtd
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/ DTD/xhtml11.dtd">
%xhtml11.dtd;
- <!-- Bring in the Target Module -->
<!ENTITY % xhtml-target.mod
PUBLIC "-//W3C//ELEMENTS XHTML Target 1.0//EN"
"http://www.w3.org/TR/ xhtml-modularization/DTD/ xhtml-target-1.mod">
%xhtml-target.mod;
However, now I have to bid farewell to that bizarre old friend: the working draft of XHTML 1.1 Second Edition includes the target
module in the core set, finally. I’m relieved because tinkering with DTDs is a pain, but it had style …
Note that in the current version target
is not yet included in XHTML 1.1 Schema, but I have been assured it will definitely be in the final version.
[…] Martin Kliehm weist zu Recht darauf hin, dass das target-Attribut auf wundersame Weise seinen Weg zurück in das Core Set von XHTML 1.1 gefunden hat. […]
[...] Martin Kliehm Martin Kliehm presenterar ett sista alternativt sätt att öppna länkar i nytt fönster, och det är att använda sig av XHTML 1.1 och modifiera DTD:n. Genom att importera target-modulen gör man target-attributet möjligt att använda. Detta verkar krångligt och är väl inte heller så aktuellt, eftersom XHTML 1.1 ändå inte kan tolkas av Internet Explorer. [...]
I was searching for an answer to the question of whether
_blank
is still valid XHTML when I found this page.After quite a bit of Googling and reading, I also found the following very simple, very elegant answer, which I tested successfully in Firefox 2.0, IE7, and Opera 9.21 and which validates at validator.w3.org as XHTML 1.0 strict and XHTML 1.1 (with the proper declarations, of course):
It was in comment #19 in the comments section of this Web page.
Marina, adding some
onclick="target='_blank'"
is indeed simple. Like I said, extending the DTD is a pain with some drawbacks. Jesse Skinner’s solution is slightly more complicated, but it works unobtrusive, without inline JavaScript. So it’s better maintainable. In the end it’s a political decision, it’s about your own preferences. There is no best solution.Thanks!
On thinking about it further, Jesse’s solution is a better one from the elegant standpoint, since you define the class and let the code do the work.
I was actually researching this for someone else, since I don’t like to open new windows.
The target attribute isn’t just for opening new windows. Using the
object
tag to embed one document in another should allow fortarget="_parent"
or"_top"
to work as well.This was a really good post, especially the misinformation part. (And the good news for the next edition of XHTML.)
I use javascript on new windows anyways (because I typically only use them for little ones that I want a certain size) but I always let my pages fail with the
target=""
error out of protest.No more failed pages, hooray!
There is a JavaScript workaround. Very compact when used with the Mootools framework.
All those hacks with onclick=”target=’blank’” is nonsense! While your page is XHTML valid, your Javascript isn’t. I mean, if some browser is able to open link in new tab with that javascript, it will definately open new tab with simple target=”_blank” declaration. And if it doesn’t understand the target attribute (because XHML doesn’t require it to), I don’t think that whole page will broke if you leave that target attribute in the “a” tag. And the solution with Javascript still won’t work. All you get from all those hacks is green tick in the validator. I mean, if all those XHTMLs were created to make user experience better, these hacks just make it worse. If user doesn’t have Javascript, _blank won’t work for him. And I think not having Javascript (enabled) is far more often than browser without target attribute support.
Thinking about users, I’ll definately still use target=”_blank” attribute in my pages. And if I’d want that green tick very badly, I’d go with that DTD expanding, because it’s only between your page and validator, don’t get users involved into this.