target=”_blank” XHTML 1.0 Strict Conversion
Please subscribe to our RSS feed for new articles. We report on Wordpress news, themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. You can also receive updates from this blog via email if you want that method of notification.
I was referred to this by tcervo through the WordPress forums and I wanted to document it. I am not a big proponent of opening new browser windows with links on my pages, but sometimes it needs to be done. However, using target=”_blank” will break XHTML 1.0 Stric validation. A couple of people have come up with fixes for this. The simplest turns out to be a peice of Javascript documented here Basically instead of using
<a target=”_blank” href=”http://blahblah.com”>new link</a>
you would use
<a rel=”external” href=”http://blahblah.com”>new link</a>
and the javascript would do the job of matching the rel tag and putting out a new browser window.
In my opinion, there comes a time when compliancy gives way to over enthusiasm and we might be reaching the limit in this case. In order to use a well documented (albeit arcane) HTML feature and keep it compliant with XHTML, one has to go around the block, add slow code and make things more complicated than they have to be. *Shrug*
If you know of a better method, please leave a comment so I can add yours to the list.

(20 votes, average: 3.95 out of 5)









Comments RSS
Well, I suppose we could use XHTML Transitional instead…but why would we want to do that
(Before anyone starts a rant about Strict vs. Transitional, keep in mind we’re talking about blogs here…which tend to be more cutting edge. Using Transitional on a commercial site is, in many cases, the better choice.)
[Reply]
Tony Cervo (1 comments.) — 01/21/2004 @ 8:00 pmApologies for the previous comment — my 2-year old son got to the keyboard…
Anyway, another way of doing it is
Some Other Site
(spotted on http://www.phpfreaks.com/quick.....ve/231.php)
But I think I prefer the method referred to here.
[Reply]
David Sterratt — 02/21/2004 @ 4:57 pmI meant to say:
<a”window.open(this.href,’_blank’);return false;” href=”http://some_oother_site.com”>Some Other Site</a>
[Reply]
David Sterratt — 02/21/2004 @ 4:59 pmThe best method is just to define a new DTD with the attribute you need.
http://dionidium.com/2004/05/xhtml-tests
[Reply]
nemo — 08/10/2004 @ 3:51 pmAnybody know how to get around the XHTML validation requirement that you can’t put an “a” tag inside a text box (for easily copying text for someone to link to your site? If so please post. Many thanks…
[Reply]
Steve Hill (1 comments.) — 02/16/2007 @ 10:52 pm[...] compliant Here is another idea, and it is xhtml strict compliant… Weblog Tools Collection » Blog Archive » target=”_blank” XHTML 1.0 Strict Conversion __________________ Startpage Ireland | PDA Startpage Ireland | Proxy List | Irish Websites | [...]
Correct anchor syntax for xhtml - Irish SEO, Marketing & Webmaster Discussion — 04/20/2007 @ 2:32 pmSteve, if you ever come back, use < and > instead of < and >. Since you’re displaying the characters themselves on the page, not using them, you want to use the html entity sequences.
[Reply]
Braden (1 comments.) — 05/15/2007 @ 7:18 pmThanks for the help! I’ve been needing this information. I wish they would have just kept the target attribute. Sure would be easier.
[Reply]
Nathan Libbey (1 comments.) — 08/24/2007 @ 12:26 pmI’v read along the way on other solution for this.They used DTD as an extension with the Strict DTD already defined. Any comment about that?
[Reply]
francis — 03/2/2008 @ 11:45 amhow about this:
<a href=”www.google.com” rel=”external” onclick=”this.target=’_blank’;”>external link</a>
[Reply]
dUcA (1 comments.) — 09/4/2008 @ 2:36 pmdUcA
rel=”external” onclick=”this.target=’_blank’;”
uses the current window, at least when I try it
[Reply]
Baer — 09/9/2008 @ 1:30 pm