哇,我这个问题迟到了9年。干得好:
// 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);
Chrome:受支持(自46开始)
Firefox:受支持(自46开始)
IE / Edge: (尚..)
Opera:受支持(自33起)
Safari:受支持
对于IE / Edge,如果要在其自动向下滚动后重新滚动到顶部,则对我有用:
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
var isEdge = /Edge/.test(navigator.userAgent);
if(isIE11 || isEdge) {
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.
}