XHTML-valid new window links
27th February 2009
I always have to look this up. Run this on page load and give all 'a' tags the attribute rel="external" to create XHTML valid links that open in a new window. Goodbye target="_blank"
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
anchor.target = "_blank";
}
}
}
Tagged: Javascript and XHTML
Comments and corrections to @edvanbeinum