I am using the script to reload the page every 10 seconds. I want to retain the scroll position even after the refresh. The following is my script:
<script type="text/javascript" language="javascript">
var idleInterval = setInterval("reloadPage()", 10000);
function reloadPage() {
location.reload(false);
}
</script>
you can do something like this :
window.addEventListener('scroll',function() {
//When scroll change, you save it on localStorage.
localStorage.setItem('scrollPosition',window.scrollY);
},false);
then on load :
window.addEventListener('load',function() {
if(localStorage.getItem('scrollPosition') !== null)
window.scrollTo(0, localStorage.getItem('scrollPosition'));
},false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With