javascript 使用javascript加载页面后如何删除以前的历史记录状态?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16368500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:20:57  来源:igfitidea点击:

How can I delete the previous history state after the page is loaded using javascript?

javascriptgoogle-chromegoogle-chrome-extension

提问by Denis Malinovsky

I would like to delete the previous history state, after the page is loaded.

我想在页面加载后删除以前的历史状态。


This is a separate question from my other question; not merely an alternative.


这是一个与我的另一个问题不同的问题;不仅仅是一个替代方案。

回答by Denis Malinovsky

If you're loading new page via JS, you can replaceits location to use the same history entry:

如果您通过 JS 加载新页面,您可以replace使用相同的历史记录条目的位置:

window.location.replace(url);

See thisanswer.

看到这个答案。

Another way is to use history.replaceState.

另一种方法是使用history.replaceState.