SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stop page from going back to top on AJAX call

    I've been working on this site:

    http://rareoopdvds.com/movie?dvd=947&movie=1441

    Below the specs of the movie on the page are tabs which load different content. Clicking a tab will send the page back to the top and load the required data.

    How can I prevent the page from popping back up like Apple does on their trailer section or youTube does in their comments?

    Thanks
    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The tab is actually an <a> tag with href="#"

    So, you are capturing the onclick event and processing it using ajax, but you're probably not returning false from the event handler. This would prevent the default action of the link (which is to jump to the top of the page in the case of #).

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes exactly do it like this:
    Code html:
    <ul>
    	<li class="detailmenu"><a href="javascript:void(null);" id="details" class="">Details</a></li>
    	<li class="detailmenu active"><a class="active" href="javascript:void(null);" id="amazon">Amazon</a></li>
    Marketplace</a></li>//-->
    </ul>

    It will solve the problem.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, the javascript:void(null) was the ticket here.
    Both comments appreciated.

    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That will of course produce a broken link if JavaScript is disabled. If you don't want it to link to somewhere if javaScript is disabled then why are you using an <a> tag to attach the onclick instead of attachhing it to a styled <span> tag.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •