Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

External links

Simple javascript function that goes through all "a" tags and checks if attribute "rel" is set to "external". If yes, then function automatically ads target="blank" attribute thus opening link in new window.

function externalLinks() 
{
    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";
        }
    }
}

Similar thing might be used when rewritting tag attributes, like rewriting css classes


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus