Tuesday, 28 April 2009 19:06

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.

Last Updated on Tuesday, 28 April 2009 19:21
 

Add your comment

Your name:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.

Santorum
Joomla Extensions