Return to Snippet

Revision: 11411
at February 4, 2009 11:16 by chippper

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

Initial URL

Initial Description
Rather than using target="_blank", which is deprecated by the W3C in XHTML, you should use rel="external" for links that you want to pop out in a new window. This is the javascript that makes it happen.

Initial Title
Open Link in an External Window via Javascript

Initial Tags
javascript, window

Initial Language