1

When I read an online page (for example: https://www.example.com/page.html) and I scroll down until, let us say, the X paragraph on the bottom of the page.

How come when I refresh the page, I find myself landed on the same X paragraph? I mean why the scrollbar of the browser stays on the same distance? I am curious to know which mechanism allows this.

Billal Begueradj
  • 295
  • 2
  • 4
  • 18

1 Answers1

1

There's a bit of HTML/JavaScript magic going on here. There's a StackOverflow answer which explains it: https://stackoverflow.com/questions/17642872/refresh-page-and-keep-scroll-position

and here: https://stackoverflow.com/questions/7577897/javascript-page-reload-while-maintaining-current-window-position

they both work by setting cookies on your position so the browser has a way of remembering it.

bearmohawk
  • 208
  • 1
  • 8
  • I believe Chrome and likeminded browsers do this automatically. – LPChip Aug 10 '17 at 14:40
  • that's possible, but I've only found JS ways of doing it.. @LPChip – bearmohawk Aug 10 '17 at 14:42
  • Thank you for the feedback, but I tried simple HTML webpages I codeded myself (without any client side scripting) and I observed the same behavior on Chrome. – Billal Begueradj Aug 10 '17 at 14:42
  • 1
    Note that if you do a "hard" refresh, ignoring cached data (`Ctrl-F5` on several browsers), then you will go to the top of the page. – AFH Aug 10 '17 at 14:43
  • I suggest pasting in the code people suggested on StackOverflow, and then seeing what happens... @BillalBEGUERADJ – bearmohawk Aug 10 '17 at 14:43