0

When a page is reloaded, it automatically retains the scroll position. How is it happening?

I need the page to scroll back to the top on each reload.

Draken
  • 3,134
  • 13
  • 34
  • 54
Mahi
  • 69
  • 2
  • 8

1 Answers1

2

Add this to your page between <script> tags:

window.onbeforeunload = function () {
  window.scrollTo(0, 0);
}

This will reset the scroll position when the page is about to unload.

Gorka Hernandez
  • 3,890
  • 23
  • 29