SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* User Jmi's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting the href bit of an <a>

    I am not really that good with javascript, but is there a way by javascript to get the href location of and <a>?
    I am trying to write a javascript function that is able to read a html document, detects if there are links, and if there are, open them in a new windows.
    Signature not found.

  2. #2
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe if javascript has a real expression parser
    Free Science Homework Help
    http://www.physicsforums.com

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This works for me:
    Code:
    <a href="<a href='http://members.aol.com/grassblad">GrassBlade</a>
    <script language="javascript">
    alert(document.links[0].href)
    </script>
    The links are maintained as an array within the document; therefore the DOM is 'document.links'
    If you want to get all of the links within a page, you simply step through the array:
    Code:
    for (var i = 0; i < document.links.length; i++)
    alert(document.links[i].href)
    Vinny
    Last edited by Vincent Puglia; Aug 29, 2003 at 05:13.
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    ********* User Jmi's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks to both of u, I'll give it a go
    Signature not found.

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if there are links, and if there are, open them in a new windows.
    You do realize that popUp blockers will not open 'automatic' windows, right?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •