History: scrollRestoration property - Web APIs | MDN (original) (raw)

Baseline

Widely available

The scrollRestoration property of the Historyinterface allows web applications to explicitly set default scroll restoration behavior on history navigation.

Value

One of the following:

auto

The location on the page to which the user has scrolled will be restored.

manual

The location on the page is not restored. The user will have to scroll to the location manually.

Examples

Query the current scroll restoration behavior

const scrollRestoration = history.scrollRestoration;
if (scrollRestoration === "manual") {
  console.log(
    "The location on the page is not restored, user will need to scroll manually.",
  );
}

Prevent automatic page location restoration

history.scrollRestoration = "manual";

Specifications

Specification
HTML # dom-history-scroll-restoration-dev

Browser compatibility