我正在寻找一种方法来更新状态栏中的网址.. 我有一个画廊,当您单击画廊时,我希望图像 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 usingreplace()
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/