History: scrollRestoration プロパティ

scrollRestorationHistory インターフェイスのプロパティで、ウェブアプリケーションが履歴の移動の動作で既定のスクロール位置の復元を明示的に設定できるようにします。

以下のうちのいずれかです。

auto

ユーザーがスクロールしたページ上のスクロールの位置が復元されます。

manual

ページ上のスクロール位置は復元されません。ユーザーが手動でその位置までスクロールする必要があります。

現在のスクロール復元の動作を問い合わせる

js
const scrollRestoration = history.scrollRestoration;
if (scrollRestoration === "manual") {
  console.log(
    "ページ上の位置は復元されないので、ユーザーが手動でスクロールする必要があります。",
  );
}

自動的にページ上の位置の復元をしないようにする

js
if (history.scrollRestoration) {
  history.scrollRestoration = "manual";
}

仕様書

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

ブラウザーの互換性

BCD tables only load in the browser