/ Published in: JavaScript
W3C no longer include the target attribute of the <a> tag in HTML 4.0 Strict and XHTML 1.0 Strict document types . To make 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$$('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' }); } } });
URL: http://www.kd3sign.co.uk/blog/post/xhtml-valid-external-links-with-mootools.html