Related Articles

2 users responded in this post

Subscribe to this post comment rss or trackback url
User Gravatar
Sebastiaan said in March 28th, 2008 at 6:24 am

That was a lot of code for such a simple thing ;-)
Here’s a smaller, usable, accessible and CSS/HTML/JS compliant method:

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”) = “_blank”;
window.onload = externalLinks;

All you do is add rel=”external” to all your links (the image to the right of the link you fix via CSS, not JS). Best is to load this little piece of script at the end of the pageload.

Greetings from the Netherlands

User Gravatar
Jake Churchill said in June 24th, 2008 at 2:50 pm

Your code will work as well. However, it provides for far fewer options and technically the “target” attribute is not a valid attribute in strict typing HTML or xHTML. See this site:

Leave A Reply

 Username (Required)

 Email Address (Remains Private)

 Website (Optional)