SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    ri
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple document.links not working...

    hi-

    i'm having some issues over here.

    i can't get this simple code to work. it should output the two links i have in the document but it doesn't output anything.

    what am i doing wrong?

    thanks!

    Code:
    <HTML>
    <HEAD>
    <TITLE> test </TITLE>
    
    <script language="JavaScript">
    
    var count;
    for (count=0; count< window.document.links.length; count++)
    {
      document.write("Link " + count + ": " + window.document.links[count] + "<BR>");
    }
    
    </script>
    </HEAD>
    
    <BODY>
    <BR>
    test
    <BR>
    <a href="http://www.walmart.com/">111 tester</a>
    sd afa sd
    <BR>
    <a href="http://www.buy.com/">222 tester</a>
    fds afasd
    <BR>
    <a href="../section11/lesson11.htm">333 tester</a>
    </BODY>
    </HTML>

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    ri
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm it seems my problem was trying to access the links, before they were loaded. so i solved that problem by doing a window.onload=function() call instead to make sure the links are loaded

    now another one:

    is there a way to extract just the domains of the links?

    for example if the .href was:
    http://www.walmart.com/product/page/49934.html

    to extract only
    walmart.com
    ?

    is there some kind of host attribute? if not can you suggest a method of doing this?

    thanks!

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    location.host will give you www.walmart.com, I guess you could strip out the www from that.


Bookmarks

Posting Permissions

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