jeffchannell.com

XHTML Strict and Link Targets

Posted in JavaScript
2009-04-29 00:06:38 +0000 UTC

Valid XHTML Strict doesn't support the 'target' tag for links, but some webmasters (me included) don't like the idea of having external links draw our visitors away, possibly to never return. That's why the 'target' tag is great - external links can open new windows (or tabs, browser willing), right?

Well, there are all kinds of solutions out there, but here's mine, written for Mootools 1.11 (thus Joomla! 1.5 core):

window.addEvent( 'load', function( e )
{
	$$('a[rel^=target:]').each( function( el )
	{
		el.target = el.rel.replace( /^target\\:/, '' );
	});
});

Now when I write code, instead of writing links the old way:

<a href="#" target="_blank">LINK</a>

...I can store the target in a strict-safe attribute:

<a href="#" rel="target:_blank">LINK</a>

Granted, this won't work on browsers that have JavaScript absent or off, but for most users it should suffice nicely.