Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retaining browser scrollbar position after page reloading

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is inherent behavior of the browser.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic