How to Disable Scroll History Restoration in Browser using Javascript

It’s default feature of browser that it saves scroll history. Suppose you scroll half window, now refresh browser will load from the half window. But sometimes we need a custom arrangement for this behavior of browser and disable this scroll history. To manipulate history of browser there is history api. Also, there is a blog post in google developer blog to clear this.

I found two polyfill that helps to make this work in all most all modern browser except IE Edge.

  1. https://github.com/bfred-it/scroll-restoration-polyfill
  2. https://github.com/brigade/delayed-scroll-restoration-polyfill

Just include the polyfil and override the history restore behavior of browser

https://gist.github.com/manchumahara/1d0ea8468d53ef0a6e524b93e1ccc56a

Leave a Reply

Your email address will not be published. Required fields are marked *