/ Published in: JavaScript
URL: http://www.kd3sign.co.uk/blog/post/xhtml-valid-external-links-with-mootools.html
W3C no longer include the target attribute of the 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
$$('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' }); } } });
You need to login to post a comment.
