Is there a way to disable the behavior where some modern browsers (Chrome and Safari) remember your scroll position on a page refresh?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Have you tried firing this after document is ready?
if that does not work...
Which will push this to the bottom of the call stack
I think the easiest way would be to trick the browser into a reload that it thinks is a new page.
All the browsers I've tested this in it works consistently. I would personally stay away from onload callbacks as they can cause jumps during load that aren't too visually appealing.
Instead of hoping a setTimout ends up at the bottom of the stack - I rather enforce it that we hit the scroll position we want. I still consider this a hack, I was hoping for some kind of browser event we bind to.
I encountered this same issue. Here's the basic solution I came up with:
For browsers that support history.scrollRestoration, the auto scroll behavior can be turned off:
source: https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration
not just for chrome,but for all i think this will work well.
After update of your question:
I think its better if we use some cookies or session storage.