History: scrollRestoration プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

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

auto

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

manual

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

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

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

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

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

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scrollRestoration

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support