XHTML valid external links with mootools
posted on 12th Jun, 2009 in JavascriptW3C no longer include the target attribute of the <a> tag in HTML 4.0 Strict and XHTML 1.0 Strict document types . To make our links open new windows we will have to use Javascript, and with mootools it make this task very easy. Just add this snippet to the bottom of your html document and it will look for all external links on your page and add the target attribute to each of the links.
$$('a[href^=http]').each(function(a) {
if (window.location.hostname) {
var hostname = window.location.hostname.replace("www.", "").toLowerCase();
if (!a.get('href').contains(hostname)) {
a.set({
'target': '_blank',
'class': (a.get('class')) ? a.get('class') + ' external' : 'external'
});
}
}
});
Bookmark with
Subscribe

