gpt4 book ai didi

javascript - 跳转到指定 anchor 而不更改历史记录

转载 作者:行者123 更新时间:2023-12-03 11:10:43 32 4
gpt4 key购买 nike

我有一个页面 foo.html,其中有很多命名 anchor 。用户从 #anchor1 跳转到 #anchor2 等。但是当用户重新加载页面时,我只想加载 foo.html 而不是 foo.html#anchorX。此外,当用户点击后退按钮时,他们应该被带到 foo.html 之前所在的页面,而不是返回到最后一个 anchor 。这可以吗?

location.replace() 负责后退按钮。但它并没有解决重新加载的问题。

最佳答案

只需在页面开头放置一个删除哈希值的脚本即可。这样每次刷新时它都会给你 foo.html。

例如

<head>
<script>
document.location.hash='';
</script>
</head>

关于javascript - 跳转到指定 anchor 而不更改历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27608837/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com