javascriptjqueryhtmlpageloadpage-refresh

Force page scroll position to top at page refresh in HTML


I am building a website which I am publishing with divs. When I refresh the page after it was scrolled to position X, then the page is loaded with the scroll position as X.

How can I force the page to be scrolled to the top on page refresh?


Solution

  • You can do it using the scrollTop method on DOM ready:

    $(document).ready(function(){
        $(this).scrollTop(0);
    });