H
hutch
Hi,
I'm making use of this VERY useful function for a so called 'standards
compliant' replacement for target="_blank":
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors;
if (anchor.getAttribute("href") && anchor.getAttribute("rel") ==
"extlink") anchor.target = "_blank";
}
} window.onload = externalLinks;
and using it with:
<a href="mylink" rel="extlink" class="extlink">link text</a>
What I'd really like to do is make it even better and do away with the
'rel', and have it that each anchor with the "extlink" class applied to
it gets processed by the function.
I have tried replacing the relevant code with this line:
if (anchor.getAttribute("href") && anchor.getAttribute("class") ==
"extlink") anchor.target = "_blank";
cut i get 'null' as the response [i alert
'anchor.getAttribute("class")']
So any ideas why this doesnt work?
Eventually I'd like to have it that all I need to do is apply the
'extlink' class to a link, and it'll be styled as I want it AND open in
a new window.
Any pointers appreciated,
Ben
I'm making use of this VERY useful function for a so called 'standards
compliant' replacement for target="_blank":
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors;
if (anchor.getAttribute("href") && anchor.getAttribute("rel") ==
"extlink") anchor.target = "_blank";
}
} window.onload = externalLinks;
and using it with:
<a href="mylink" rel="extlink" class="extlink">link text</a>
What I'd really like to do is make it even better and do away with the
'rel', and have it that each anchor with the "extlink" class applied to
it gets processed by the function.
I have tried replacing the relevant code with this line:
if (anchor.getAttribute("href") && anchor.getAttribute("class") ==
"extlink") anchor.target = "_blank";
cut i get 'null' as the response [i alert
'anchor.getAttribute("class")']
So any ideas why this doesnt work?
Eventually I'd like to have it that all I need to do is apply the
'extlink' class to a link, and it'll be styled as I want it AND open in
a new window.
Any pointers appreciated,
Ben