更改window.location.href后无法返回 [英] Can't go back after changing window.location.href

查看:1856
本文介绍了更改window.location.href后无法返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,我正在跟踪使用

In my script I'm tracking what tab I am on in a web page using

window.location.href = #!hashName1

如果我再单击另一个选项卡,它将转到#!hashName2

If I then click on another tab, it will go to #!hashName2

我的问题是,如果单击后退按钮,它将回到状态#!hashName1.然后,我必须再次单击上一步"以返回另一页.

My issue is, if I click the back button, it just goes back to the state #!hashName1. I have to then click back once again to go back another page.

有什么办法让它返回页面而不返回到先前的哈希状态?

Is there any way to just have it go back a page and not back to the previous hash state?

谢谢

推荐答案

以下内容可完美运行:

我更改了:

window.location.href = #!hashName1

history.replaceState("", "", #!hashName1);

这篇关于更改window.location.href后无法返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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