PDA

View Full Version : rel="external" in place of target="_blank"


Atul
23-06-2008, 03:31/03:31AM
The code for using rel="external" is -

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;

Please specify how it works. Can we use rel="external"
without JS.

chrishirst
25-06-2008, 07:10/07:10AM
not sure what you are asking or why, come to think of it, but the code you posted will make a array of ALL anchor elements in the document, check if it has an "rel" attribute value of "external", then, if so, insert a target attribute value of "_blank".

It is probably being used to workaround the target attribute being deprecated in XHTML doctypes other than a frameset DTD, to make external links open in a new window.


if you want to add rel="external" to links, just do so.