gpt4 book ai didi

javascript - 在不破坏历史记录的情况下,用 javascript 更新 URL 参数?

转载 作者:行者123 更新时间:2023-11-29 18:35:32 25 4
gpt4 key购买 nike

我正在寻找一种方法来更新状态栏中的 url..我有一个画廊,当您在画廊中单击时,我希望图像 ID 显示在 URL 中,以便用户可以直接链接到图像。

我读过有关使用哈希等的内容。但据我所试,这“毁了”历史。如果我在浏览器中单击后退按钮,则会显示上一张图像。

是否可以在不破坏历史记录的情况下添加或更新 URL 参数?

提前致谢

最佳答案

使用location.replace替换当前位置:

Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

关于javascript - 在不破坏历史记录的情况下,用 javascript 更新 URL 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661811/

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