Return to Snippet

Revision: 55537
at February 10, 2012 17:40 by Krummelz


Initial Code
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}
window.onload = externalLinks;

Initial URL
http://www.sitepoint.com/standards-compliant-world/

Initial Description
Usage:
&lt;a href="http://www.whaterver-your-site-is-called.com/" rel="external"&gt;Some other site&lt;/a&gt;

Initial Title
Javascript open links in a new window, without _blank

Initial Tags
links

Initial Language
JavaScript