wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Retaining browser scrollbar position after page reloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Retaining browser scrollbar position after page reloading" Watch "Retaining browser scrollbar position after page reloading" New topic
Author

Retaining browser scrollbar position after page reloading

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
Just like javaranch pages, how do I, using either html or javascript, retain the scrollbar position even though the page reloads, e.g. by pressing 'refresh' of browser.

I noticed that javaranch pages are like that. If I am currently at the bottom of the page, and I click the browser's 'refresh' function or F5, the page reloads, and the focus is returned to the bottom of the page.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Anchors. Note the part after the # in the URL and the anchor names or element ID's in the HTML source.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
I am not sure if you got what I meant.

Try go to http://www.javaranch.com/

Then scroll the page down to the bottom (this page is long so you would be like 4 screen-full down) of the page.

Then do a refresh by PF5 or the browser's refresh trigger like a button.

You will see that the javaranch page reloaded with the latest data from server, then went back to bottom of page - the same scroll location where you were.

We are talking about random/dynamic locations, not pages with #.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

My browser does that too. I think it is being smart and remembering for me. There certainly isn't any code that does it in the forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

This is inherent behavior of the browser.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
Thank you.

Now, just to play with it, I will try to force it by code. I will try using onload/unload of javascript, and cookies. If you got ideas, it will appreciated.
 
 
subject: Retaining browser scrollbar position after page reloading
 
Similar Threads
Editing HTML page in eclipse
UBBCode v HTML tags
page relaod probem- resending data to servlet
Positioning the scroll bar..
scroll bar