刷新页面后禁用浏览器的自动滚动功能? [英] Disable brower's auto scroll after a page refresh?

查看:671
本文介绍了刷新页面后禁用浏览器的自动滚动功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以禁用某些现代浏览器(Chrome和Safari)记住页面上的滚动位置刷新的行为?

Is there a way to disable the behavior where some modern browsers (Chrome and Safari) remember your scroll position on a page refresh?

推荐答案

对于支持history.scrollRestoration的浏览器,可以关闭自动滚动行为:
$ b

For browsers that support history.scrollRestoration, the auto scroll behavior can be turned off:

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

来源:https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration

这篇关于刷新页面后禁用浏览器的自动滚动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆