Page 1 of 1
document.getElementsByTagName??
Posted: Sun Jan 11, 2004 9:45 am
by d3ad1ysp0rk
I've been looking around, and I found this code, that if you enter this into a browser window, it will get the contents of a hyperlink (the part in bold):
Code: Select all
<a href="http://www.google.com/">їb]Google.comї/b]</a>
but im not so sure how to get the attribute for href (ie. getting "
http://www.google.com/" instead of "Google.com"..
Code: Select all
javascript:w=window.open("");
a=document.getElementsByTagName("a");
for(c=32;c<98;c++)
for(i=0;i<3;i++)
w.document.write("<iframe src='http://www.site.com/page.php?name="+aїc].innerHTML+"' width='100' height='100'></iframe>");
void(0);
(its all one line, so you can paste it into your browser, but i added line breaks so u can read it..)
any ideas or functions that would do this?
thanks
Posted: Sun Jan 11, 2004 5:27 pm
by scorphus
The toString() method of the A class returns the href attribute of the object. Thus either you do:
Code: Select all
w.document.write("<iframe src='http://www.site.com/page.php?name="+a[c].href+"' width='100' height='100'></iframe>");
or just:
Code: Select all
w.document.write("<iframe src='http://www.site.com/page.php?name="+a[c]+"' width='100' height='100'></iframe>");
These are not PHP, just using syntax-highlighting

Posted: Sun Jan 11, 2004 5:39 pm
by Gen-ik
Don't forget that getElementsByTagName() will only work on browsers that are DHTML compatible... ie IE5.5+ and NS6+ (not too sure about other browsers) so it might be worth having some kind of browser detection on your site.
Come to think of it you could find out simply by using
Code: Select all
var isDHTML = document.getElementById != -1 ? true : false
Posted: Mon Jan 12, 2004 9:59 pm
by d3ad1ysp0rk
Thanks a lot you guys

Posted: Sun Sep 12, 2004 1:39 am
by anjanesh
I was working on getting the <a> tags of all urls ending with bz2.
var ela=document.getElementsByTagName("A");
for (i=0;i<ela.length;i++)
{
if (ela.item(i).href.substr(-3,3)=="bz2")
txtLinks+=ela.item(i).Name+" : "+ela.item(i).href+'<BR>';
}
But name is undefined, How do I get the name (caption or whatever) ?
<A HREF="url.php">ThisName</A>
tagName will return A
href will return url.php
what will return ThisName ?
Posted: Sun Sep 12, 2004 2:48 am
by feyd
I don't remember a Name property.. maybe a name property...
you can try .innerHTML too.
Posted: Sun Sep 12, 2004 2:53 am
by Gen-ik
Yep, innerHTML will do the trick. Just replace "ela.item(i).Name" with "ela.item(i).innerHTML" and it should chuck out what you need it to
