history.replaceState仍然将条目添加到“浏览历史记录”中。 [英] history.replaceState still adds entries to the "Browsing History"

查看:299
本文介绍了history.replaceState仍然将条目添加到“浏览历史记录”中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,调用以下代码片段:

Specifically, calling the following snippet of code:

history.replaceState(undefined, undefined, "#" + value)

将正确地影响当前页面的后退按钮行为,但在浏览历史记录页面中添加一个我不想要的条目。下图是Chrome的历史记录页面,但这也发生在Firefox中。

will correctly not affect the back button behavior of the current page, but will add an entry to the "browsing history" page, which I don’t want. Pictured below is Chrome’s History page, but this also happens in Firefox.

有没有办法在不添加用户浏览历史记录的条目的情况下替换当前的URL?

Is there some way to replace the current URL without adding an entry to the user’s browsing history?

我正在询问独立的浏览器历史记录页面,而不是后退按钮使用的实际页面导航历史记录。

I’m inquiring about the standalone Browser History page, not the actual page navigation history that the Back button uses.

推荐答案

使用replaceState方法的正确方法。
在我做的测试中,它在chrome和firefox中运行良好 - 运行replaceState后历史记录没有改变。

The correct way to make it is using the replaceState method. In the tests that I did, it's working very well in both chrome and firefox - the history has not changed after running replaceState.

这篇关于history.replaceState仍然将条目添加到“浏览历史记录”中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆