SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Changing HREF

  1. #1
    SitePoint Addict
    Join Date
    Dec 2003
    Location
    South Korea
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing HREF

    I have a link lets say looks like this:
    <a href="#" onclick="parent.aframename.location='http://sitepoint.com'">Click here to go to Sitepoint</a>

    Now, i want to have it so that when i click this link, the href changes BUT DOES NOT redirect/go to the new href/ reload the page. I want it to stay on the same page, just the href changes in the background. The new link would look something like this:

    <a href="#" onclick="parent.aframename.location='http://newurl'">Click here to go to Sitepoint</a>

    I kno you could do this by clicking a button such as this (http://www.w3schools.com/js/tryit.as...om_anchor_href), but i want to do it all in one step by just clicking the link itself.

    Any help would be appreciated.

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you just need to call the function with onclick and return false to prevent the link from being activated. It should be noted that the innerText object property used in the W3C example is IE only. If you wish to alter text within the link, innerHTML is better supported and can accomplish the same thing.


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
  •