For instance, I open a web page, and scroll down to some position,
then I refresh the chrome browser, the browser could scroll the previous position again
How can I use javascript or css to let the browser to forget the scroll?
I have try $(window).scrollTop(0)
, but it doesn't work
store the position in cookies and after that use the cookie to scroll the page to exact position .
It is resolved in the question below.
Disable brower's auto scroll after a page refresh?
// bypass auto scrolling.
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
A simple way that I can say is to run this code on page load:
document.location = "#";
OR
window.scrollTo(0);
It set the browser viewport to the top of the page, again.
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