View Single Post
  #9 (permalink)  
Old Feb 10th, 2008, 20:03
Ed Ed is offline
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 688
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

Quote:
Originally Posted by imagn View Post
You can use the following JS function to mimic the target attribute. On your links you would use:

rel="external" instead of "target=_blank"

===================================

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

===================================

Note: If you have other "onload" elements within your body tag you'll need to move the call in the function to within the body tag.
We know that! It mimics something that isn't valid. Why on Earth would you want to do that? You might as well just use the target attribute, because all this does is do the same thing without the Validator noticing.

At WebForumz, we try to improve on standards, and follow the guidelines set by W3C, not find loopholes so we can exploit them!

Ed.