History.scrollRestoration - Web APIs 编辑
The scrollRestoration
property of History
interface allows web applications to explicitly set default scroll restoration behavior on history navigation.
Syntax
const scrollRestore = history.scrollRestoration
Values
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
if (history.scrollRestoration) {
history.scrollRestoration = 'manual';
}
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'scroll restoration mode' in that specification. | Living Standard | No change from HTML5. |
HTML5 The definition of 'History.scrollRestoration' in that specification. | Recommendation | Initial definition. |
Browser Compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论