javascript - 使用 javascript 更新 URL 参数,而不破坏历史记录?

标签 javascript url parameters hash

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

相关文章:

javascript - 出现错误无法读取未定义的属性 'getTime'

iphone - 启动 Apple 的股票应用程序,并选择特定股票

url - Drupal 7 : URL alias is getting ignored on pages when "provide a menu link" is unchecked on multilingual site

java - 如何在转发时将请求参数从一个 servlet 传递到另一个

javascript - 如何定位我想要使用 GPT 刷新的广告

javascript - 带有子路由器的 Aurelia-Router 显示警告

javascript - 我怎样才能实现这个水平搜索结果栏?

actionscript-3 - AS3 URL 字符串 -> URLRequest

c++ - 使用 Boost 的 program_options 处理复杂的选项

.net - Activator.GetObject - 使用状态参数