History.scrollRestoration

翻译不完整。 请帮助我们翻译这篇文章!

{DOMxRef("History"))的接口——滚动恢复属性允许web应用程序在历史导航上显式地设置默认滚动恢复行为

语法

const scrollRestore = history.scrollRestoration

auto
将恢复用户已滚动到的页面上的位置。
manual
未还原页上的位置。用户必须手动滚动到该位置。

案例

查看当前页面滚动恢复行为

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

防止自动恢复页面位置

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

规范

规范 状态 评论
HTML Living Standard
scroll restoration mode
Living Standard No change from HTML5.
HTML5
History.scrollRestoration
Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollRestorationChrome Full support 46Edge Full support 79Firefox Full support 46IE No support NoOpera Full support 33Safari Full support YesWebView Android No support NoChrome Android Full support 46Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support