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?
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?