PDA

View Full Version : Using rel="external" with AJAX loaded content


nicky77
01-31-2008, 10:32 AM
Hi, I seem to be having a problem using rel="external" on links within a div where the content is loaded dynamically with AJAX. Is there a way round this? There is no problems with using external links on the part of the page which does not change, so the code etc should be fine.

The following code is the javascript function, stored in external.js:

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;


in the head of my main page, i call the script with
<script type="text/javascript" src="includes/external.js"></script>

and for all of the links i want to open in a new window i simply add rel="external", e.g <a href="http://www.paul-young.com/" rel="external">CLICK HERE</a>

any ideas where i'm going wrong here?

BatCountry
01-31-2008, 02:21 PM
just a question, why are you adding rel="external" with javascript? I mean the rel tag is for telling spider bots what the relationship of a link is to a page, and since most spiderbots don't execute javascript and only look at the direct source (rather then the source after js execution) - it means they won't see the rel="external" on the links.