SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: AJAX Links

Hybrid View

  1. #1
    SitePoint Zealot alfred3x's Avatar
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX Links

    I'm developing a couple of AJAX-based data browsers, and I'm delighted with the response times and the look and feel of the pages. The one issue I'm having right now is with page positioning. When I click on a link which refreshes the browser with new content, it jumps back to the top of the page.

    Ideally I'd like it to remain where it is.

    The code for the link looks like so:

    Code:
    <a href="#" onclick="fetchCategories(this, 12345, 67890);"></a>
    fetchCategories() returns false.

    I'm guessing that just returning false doesn't seem to be enough. You actually have to put in a return false; at the end of the onclick.

    Can someone explain why this is, and how this works?

    Thanks.
    - A. Alfred Ayache
    PHP/MySQL ZCE

  2. #2
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can set the name of the anchor.

    Code:
    <a href=#stayhere" name="stayhere" onclick="fetchCategories(this, 12345, 67890); return false;" ></a>
    I think that should work.
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  3. #3
    SitePoint Zealot alfred3x's Avatar
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that suggestion, rich, but that item actually gets trashed by the AJAX refresh. I'm trying to figure out how to not move the page at all, and putting a link like that specifically moves it.
    - A. Alfred Ayache
    PHP/MySQL ZCE

  4. #4
    SitePoint Zealot alfred3x's Avatar
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I figured it out! The original code was:

    Code:
    <a href="#" onclick="fetchCategories(this, 12345, 67890);"></a>
    I tried moving the onclick JavaScript into href, but then that code shows up in the status bar. That's when I remembered javascript:void(0);. So the final code is:

    Code:
    <a href="javascript:void(0);" onclick="fetchCategories(this, 12345, 67890);">whatever...</a>
    I'm not crazy about the javascript:void(0); appearing in the status bar, but I can live with that.

    The only way the page jiggles now is when the code affects the length of the page.

    Thanks for your help.
    - AAA
    - A. Alfred Ayache
    PHP/MySQL ZCE


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
  •