scrollRestoration property of 历史 interface allows web applications to explicitly set default scroll restoration behavior on history navigation.

句法

const scrollRestore = history.scrollRestoration
					

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.

范例

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

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

规范

规范 状态 注释
HTML 实时标准
The definition of 'scroll restoration mode' in that specification.
实时标准 无变化自 HTML5 .
HTML5
The definition of 'History.scrollRestoration' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
scrollRestoration Chrome 46 Edge 79 Firefox 46 IE No Opera 33 Safari Yes WebView Android No Chrome Android 46 Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: