且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript:使用后退按钮时,防止浏览器恢复滚动位置

更新时间:2023-12-03 08:33:04

尽管是实验性的,但您可以尝试调整" manual".

Although it is experimental, you can try adjusting the History scrollRestoration from "auto" to "manual".

这里有一些可以进行填充来帮助跨浏览器兼容也是.

There are a few polyfills out there to help with cross-browser compatability too.

if ('scrollRestoration' in history) {
  // Back off, browser, I got this...
  history.scrollRestoration = 'manual';
}