www.webdeveloper.com
Results 1 to 2 of 2

Thread: Links to Array

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    1

    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:
    http://www.chatzy.com/
    If that matters.

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    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;
    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles