Enhance External Links





11
Date Submitted Thu. Feb. 9th, 2006 2:14 PM
Revision 1 of 1
Helper Iain
Tags External | JavaScript | Links
Comments 0 comments
Enhance External Links
var enhanceLinks =
{
        initialise: function()
        {
                // Check the browser can understand this script:
                if (!document.getElementsByTagName)
                        return;

                var pageLinks = document.getElementsByTagName('a');

                for (var i = 0; i < pageLinks.length; i++)
                {
                        // Check if the link leads outside the parent domain:
                        if (pageLinks[i].href.indexOf('http://' + window.location.hostname) == -1)
                        {
                                // Don't write over any existing class names:
                                pageLinks[i].className += ' external';
                                pageLinks[i].title = 'This is an external link that will open a new window (' + pageLinks[i].href + ')';
                                pageLinks[i].onclick = enhanceLinks.popup;
                        }
                }
        },

        popup: function()
        {
                window.open(this.href, 'flPopup', '');
                return false;
        }
}

Iain Gardiner

www.firelightning.com
I'm just this guy, y'know?
Fire and Lightning

Comments

There are currently no comments for this snippet.

Voting