哇,我问这个问题晚了 9 年。干得好:
将此代码添加到您的 onload.xml 文件中。
// This prevents the page from scrolling down to where it was previously.
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
// This is needed if the user scrolls down during page load and you want to make sure the page is scrolled to the top once it's fully loaded. This has Cross-browser support.
window.scrollTo(0,0);
要在窗口加载时运行它,只需像这样将它包装起来(假设您引用了JQuery)
$(function() {
// put the code here
});
history.scrollRestoration 浏览器支持:
Chrome:支持(自 46 起)
Firefox:支持(自 46 起)
边缘:支持(自 79 起)
IE:不支持
Opera:支持(自 33 起)
Safari:支持
对于IE,如果您想在它自动向下滚动后重新滚动到顶部,那么这对我有用:
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
if(isIE11) {
setTimeout(function(){ window.scrollTo(0, 0); }, 300); // adjust time according to your page. The better solution would be to possibly tie into some event and trigger once the autoscrolling goes to the top.
}