Home

External Links List Javascript

Did anyone notice the "External Links" list down the side of the main page of my blog?…Scr3w you, that took me hours to do!  My keyboard is full of blood from all the typing!

Anyhow, here’s the code.  Just remember to add your domain into it on line 5, making sure you escape periods (.) with a forward slash (\).  Enjoy :D

var links = document.getElementsByTagName("a");
var externalLinksHtml = "";
for( var i = 0; i < links.length && i < 100; i++ )
{
if( ! /keebler\.net/i.test( links[i].href ) && ! /</.test( links[i].innerHTML ) )
{
externalLinksHtml += "<li><a href=\"" + links[i].href + "\">"
+ links[i].innerHTML.substring( 0, 25 )
+ "…</a></li>";
}
}
document.write( externalLinksHtml );

 

Related Posts

Comments are closed.