Well, I keep having problems.
I'm trying to make a link harvester for this Chatroom.
Because my friends post way too many links and I never get to view them all.
So I was trying to make something to fix that.
Html is roughly:
<td style="vertical-align: bottom; font-size: 14px;" id="X110">
<p class="a">
<b style="color: Green;">asdfasa</b>:
<a target="_blank" title="Click to open in new window" href="http://www.link.com/">http://www.link.com/</a>
</p>
<p class="a">
<b style="color: Green;">asdfasa</b>:
<a target="_blank" title="Click to open in new window" href="http://www.link.com/">http://www.link.com/</a>
</p>
<p class="a">
<b style="color: Green;">asdfasa</b>:
<a target="_blank" title="Click to open in new window" href="http://www.link.com/">http://www.link.com/</a>
</p>
</td>
My javascript was:
var Links=new Array();
function XLink() {
var num = X110.getElementsByTagName("a").length;
for(i=0;num=i;i++) {
t=1;
for(q=0;Links.length=q;q++) {
if (X110.getElementsByTagName("a")[i-1].href == Links[i-1]){
t=0;
}
}
if (t){
Links[i] = X110.getElementsByTagName("a")[i-1].href;
}
}
}
I want to make sure that I'm not saving the same links over and over. So I want them to check through the array first.
But I keep getting the value undefined.
This is probably what you are trying to do. You seem to need to revise for loops, and remember that i = num and i == num are two totally different things.
Code:
function XLink () {
var links = [], as = document.getElementById("X110").getElementsByTagName("a");
out: for (var i = 0; i < as.length; i++) {
for (var j = 0; j < links.length; j++) {
if(as[i].href == links[j]) {
continue out;
}
}
links[i] = as[i].href;
}
}