-
the new target”_blank”
One of the weirder errors I got when I tried to validate my pages was for using the target”_blank” on my links.
What am I supposed to do? Just send people away from my site everytime there is a link!?
As it turns out the target attribute is not XHTML compliant. You just can’t use it.
So how do you get around it?
A little bit of Javascript helps.
First remove all those pesky targets from your links and replace them with rel=”external”
then create a new javascript page with this code:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName(“a”);
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute(“href”) &&
anchor.getAttribute(“rel”) == “external”)
anchor.target = “_blank”;
}
}
window.onload = externalLinks;And finally you just need to link to this in the head of your document.
using:
<script type=”text/javascript” src=”external.js”></script>
Now all your links with the rel external will open in new windows.
Thanks to these guys :
Posted on May 29, 2009
blog comments powered by Disqus