Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Retain vertical scroll when going back to search results

    I have a form that when submitted displays the results in rows (search.php)
    Each row has a link to more information (detail.php).

    I have the parameters in a session so that I can get back to search.php from detail.php with parameter, pagination etc intact.

    However, I need to find a way to put the scroll back to here it was when the user clicked on the 1st link (in detail.php).
    The reason for this is they may loose where they were when scrolling through the results.

    I know the scroll position can be accessed/set with jquery, but I'm not sure passing client information to php is possible. The scroll position needs to be retrieved when the user clicks on the link to detail.php and ideally put into the session, but I'm not sure how?

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    If I understand correctly, what I would suggest is having a named anchor on each result and linking back using local linking e.g.

    Code:
    Blah blah <a href="detail.php?id=1" name="link1">Details</a>
    Blah blah <a href="detail.php?id=2" name="link2">Details</a>
    Blah blah <a href="detail.php?id=3" name="link3">Details</a>
    then if link 3 was clicked (you know this in details.php anyway) you make the link back go to search.php#link3. The browser should then jump the page down to the right point automatically without needing to figure out exact scroll positons. In fact you could probably just put a named anchor on the one result that was clicked if you want to save a few bytes.

    HTH,

    Dai

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for the reply.
    This is almost working. Its fine in IE but not firefox. The page jumps to the bottom instead of for example half way.

    The strange thing is when I hit return in the address bar, the page jumps to where it is supposed to be, so the anchor is correct.

    Here is the php generating the link
    PHP Code:
    echo "<a name=\"hash".$row['ID']."\" id=\"hash".$row['CL_NO']."\"></a><a href=\"detail.php?ID=".$row['ID']."\"><strong>".$row['TITLE']."</strong></a>\n"
    and the output html

    Code:
    <a name="hashCS19" id="hashCS19"></a><a href="detail.php?ID=CS19"><strong>Title goes here</strong></a>
    Can anyone see why only firefox would jump to the bottom?
    Last edited by htcilt; 02-18-2010 at 10:06 AM.

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I've done a bit more testing.
    I currently have 20 rows returned per page. To get the scrolls, I reduced the size of the window. This is where firefox starts to fail. If I maximise the window and increase the rows returned to 80 (to gain scrollbar) it works!

    So it seems that in FF if the maximsed window doesn't need to scroll, the anchors wont work when the windows is reduced even through the scrollbar is introduced.

    IE works perfectly!

  • #5
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Sounds like a firefox, um, idiosynchrasy

  • #6
    New Coder
    Join Date
    Nov 2009
    Location
    Tampa, Florida. US
    Posts
    18
    Thanks
    5
    Thanked 1 Time in 1 Post
    I just tested this with no PHP involved....

    (just a raw unordered list of links.)
    I noticed in your example you went back to the empty link in front of the link you want... I don't understand why, did you run into an issue?
    Code:
    		<ul>
    			<li><a href="#linked">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a name="linked" href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>			
    		</ul>
    either way I shrunk the window to allow scrolling and clicked the first link (in FF) this jumped me to the proper link...

    I tried again with your setup..
    Code:
    		<ul>
    			<li><a href="#linked">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a name="linked" id="linked"></a><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>
    			<li><a href="#">Link</a></li>			
    		</ul>
    this jumped me down to the bottom just like in your issue..
    So if possible, try merging the name attribute over to the main link...

  • #7
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks blue642,

    I'll make that amend tomorrow and see if FF behalves differently.
    I think I went back to the separate anchor before the item because I was using eBay as a reference.
    But the thing with eBay is every page has a vertical scroll - even if only 1 row is returned. It might even be that the problem exists for eBay too, but isn't apparent due to the amount of scrolling involved on the results page.


  •  

    Posting Permissions

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