Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let the chrome forget the page scroll position?

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

like image 361
hh54188 Avatar asked Mar 12 '13 07:03

hh54188


People also ask

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

store the position in cookies and after that use the cookie to scroll the page to exact position .


2 Answers

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';
}
like image 165
Brian Zhang Avatar answered Oct 05 '22 18:10

Brian Zhang


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.

like image 40
Afshin Mehrabani Avatar answered Oct 05 '22 19:10

Afshin Mehrabani