How to remember scroll pos of the `div` to restore it when page is reloaded?

StackOverflow https://stackoverflow.com/questions/23448717

  •  14-07-2023
  •  | 
  •  

سؤال

I have div with absolute positioning

<div style:position: absolute; left:50px; overflow: auto; top:200px; right:100px; bottom:25px;>

Above it there is a logo etc.

But if div scrolled down and page is refreshed, the scroll of this div goes at the top of the div.

Is there any method to keep div in previous position after page's refresh?

هل كانت مفيدة؟

المحلول

please read this : How to get scrollbar position with Javascript?

Method 1 and then consider to store a cookie with the scrollbar position.

Method 2 or store the value server side in a visitors table on base of the IP

There is one more funny way.

Method 3 use anchors like <a name="foo"> and send your post action to the URL containing the anchor like this <form action="site.php#foo" ... Its not so exact like the cookie version but it works somehow :))

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top