Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome remembers scroll position

I'm running into a problem that's actually a "feature" on Chrome. As most of you might know, Chrome remembers a scroll position that it returns to, whenever you come back to a page. And I kind of have a problem with that.

Is there any way to override this without the user noticing?

Mees

Failed try-outs:

  • ScrollTop on document.ready
like image 789
amees_me Avatar asked Apr 26 '13 15:04

amees_me


People also ask

Does chrome remember scroll position?

Bookmark this question. Show activity on this post. I'm running into a problem that's actually a "feature" on Chrome. As most of you might know, Chrome remembers a scroll position that it returns to, whenever you come back to a page.

How can I retain the scroll position of a scrollable area when pressing back button?

During page unload, get the scroll position and store it in local storage. Then during page load, check local storage and set that scroll position.


2 Answers

In Chrome 46+, the auto scroll behavior can be turned off using history.scrollRestoration:

if ('scrollRestoration' in history) {   history.scrollRestoration = 'manual'; } 

source: https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration

like image 173
Cory Duncan Avatar answered Sep 19 '22 08:09

Cory Duncan


I've checked on chrome, it worked well. Sometimes setTimeout does trick :)

<script type="text/javascript"> window.onload=function(){     setTimeout(function(){         scrollTo(0,-1);     },0); } </script> 
like image 21
Ikrom Avatar answered Sep 22 '22 08:09

Ikrom