Using rel=external instead of targe _new and _blank

hi, i read that the target=“_new” and blank are not web standard.

there is a js solution… in my head i have

<script type="text/javascript" src="external.js"></script>

and on a link i use

<a href="" rel="external">

this works in ff but not ie… why… i thought this was the best practice

here is the js file.

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;

The target attribute is valid HTML. IMHO you should probably write HTML and NOT XHTML. But if you insist, Sitepoint has a good article about this that should be of help. http://www.sitepoint.com/article/standards-compliant-world

IE doesn’t even support xhtml…

But if you insist, Sitepoint has a good article about this

Uhhmmm…did you notice his code is the same as the code in the article?

this works in ff but not ie

It works in IE6 for me.

worked for me in IE6…even tried a different onload function.


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 = function() {
externalLinks();
}

I always liked

<a href=“file.cfm” onclick=“javascript:window.open(this.href);return false;” title=“click me”>Click here</a>

It’s XHTML valid, short n sweet, but DOES rely on the user having Javascript enabled.

The latest thinking in web usability is that you should let your visitors choose for themselves when they want to open a link in a new tab or window. All browsers support this via options in the context menu.

The rel=“external” script is great and I have used it. Now I want to add an event to the link using the script - I have tried adding

anchor.onmousedown = “return nav(this.href)”;

and it does not work.

Any suggestions?
How do I access all the DOM information on a page?

Colin