Forcing website to 'reload' to the top of the page

I have a site which relies heavily on where the user is on the page. I have features that happen when certain distances are reached.

I want the user to be taken to the top of the page when/if they reload the page. Currently, they reload to where they left off. However that screws up the code that depends on page position.

Answers 1

  • Something like below should work :

    $(document).ready(function() {
      $("html,body").animate({scrollTop: 0}, 50); 
    });
    

    We don't exactly know when the browser jumps to the last-scroll position. This is why some form of delay after the page has loaded is necessary. Or you could scroll to top before the page reloads.


Related Articles