清除 popstate 事件的转发历史记录
添加到历史记录中的视图。
我正在开发一个应用程序,该应用程序使用通过history.pushState()
函数
这些视图是表单中的不同步骤,用户可以在其中返回到之前的步骤并进行调整,但不得转发而不重新发布。
我通过侦听 popstate 事件并在调用的函数中向后导航一步来实现后退导航。
问题是,当调用 popstate 时,浏览器中的历史记录由于显而易见的原因而变得可点击。但由于历史前进按钮也会触发 popstate 事件,因此单击历史前进的结果是您又向后退了一步。
由于我不希望用户能够前进历史记录,因此我希望清除前进历史记录。
所以我的问题基本上是,当您向后浏览浏览器历史记录时,有没有办法删除前进历史记录?
I am developing an application which uses views that gets added to the history through
history.pushState()
function
The views are different steps in a form where a user is meant to be able to step back to previous steps and make adjustments but not forward without re-posting.
I achieve the back navigation by listening for popstate events and navigating back one step in the invoked function
The problem is that as popstate is called the history forward in the browser becomes clickable for obvious reasons. But as the history forward button also fires a popstate event the result of clicking history forward is that you navigate another step back.
Since I don't want the user to be able to go history forward I would want the forward history to be cleared.
So my question is basically, is there a way to remove forward history as you step back through the browser history?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查用户是否从下一步(步骤 2)返回,例如您可以使用 cookie 或 localStorage 来执行此操作。如果他使用当前位置执行pushState(步骤1)。不幸的是,它会在历史列表中为后退按钮添加另一个位置,但它也会禁用历史前进按钮。第 2 步在历史记录列表中不可见。它并不完美,但也许已经足够好了。
Check if user is coming back from the next step (step 2), for example you can do this using cookies or localStorage. If he is do a pushState with the current location (step 1). Unfortunately it will add another position in history list for the back button but it will also disable history forward button. Step 2 won't be visible in the history back list. It's not perfect but maybe it's good enough.