Return to Snippet

Revision: 17402
at September 3, 2009 06:57 by cherrywaves


Initial Code
$$('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'
            });
        }
    }
});

Initial URL
http://www.kd3sign.co.uk/blog/post/xhtml-valid-external-links-with-mootools.html

Initial Description
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.

Initial Title
XHTML valid external links with mootools

Initial Tags
links

Initial Language
JavaScript