• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retaining browser scrollbar position after page reloading

 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 #.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is inherent behavior of the browser.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic