/    Sign up×
Community /Pin to ProfileBookmark

Links to Array

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.

The chat site is:
[url]http://www.chatzy.com/[/url]
If that matters.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 11.2010 — 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.function XLink () {
var links = [], as = document.getElementById("X110").getElementsByTagName("a");
out: for (var i = 0; i &lt; as.length; i++) {
for (var j = 0; j &lt; links.length; j++) {
if(as[i].href == links[j]) {
continue out;
}
}
links[i] = as[i].href;
}
}
×

Success!

Help @Tubzies spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...