gpt4 book ai didi

javascript - 在不更改 url 的情况下转到 anchor

转载 作者:行者123 更新时间:2023-12-04 01:17:00 25 4
gpt4 key购买 nike

在加载页面时,我希望它转到 #content不改变网址。

我以为我可以使用

window.location.hash = "content";
window.location.replace("#content", "");

但是 #content网址上仍然存在。

有什么更好的方法吗?

编辑:

也试过
window.location.hash = "content";
window.location.replace(window.location.toString().replace("#content", ""));

但这会使浏览器陷入循环。

最佳答案

您可以找到具有该 ID 的 anchor 的垂直位置,然后滚动到该位置。

关于javascript - 在不更改 url 的情况下转到 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4020199/

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