Blog overview

#1 TIL – ScrollRestoration

Today I learned how to prevent the browser from restoring the scroll position on page load.

Scrollrestoration

By default the browser restores the scroll position of the user on page load. If you need to prevent this, you can do it with the history api.

if (history.scrollRestoration) {
  history.scrollRestoration = 'manual';
}

By setting scrollRestoration to manual the browser will no longer restore the scroll position, therefore the page always is set to the very top when reloaded. Before using this feature you should think twice, if you really want to prevent this default behaviour, because users are used to it when navigating in history.

TIL, short for Today I learned, a series of short posts with things I learn in my daily life as frontend engineer.

Blog overview