简体   繁体   English

在history.pushState之后导航时恢复原始页面

[英]Restore original page when navigating back after history.pushState

I'm using history.pushState to create a 'fake' results page after the user submits a form. 用户提交表单后,我正在使用history.pushState创建“伪造”结果页面。 However, when I navigate back, the visible page stays the same. 但是,当我向后浏览时,可见页面保持不变。 What is an easy way to get the original page - unmodified by javascript, but with the form filled out - after pressing back? 按下后,获得原始页面的简单方法是什么(通过javascript未经修改但已填写表格)?

You need to watch the current address for changes and react to it yourself. 您需要查看当前地址是否有更改,然后自己做出反应。

See this example: https://developer.mozilla.org/en/DOM/window.onpopstate 参见以下示例: https : //developer.mozilla.org/en/DOM/window.onpopstate

Also have a look at the documentation: 还可以查看文档:

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history/ https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history/

You have to handle the onpopstate event and reload the previous page manually: 您必须处理onpopstate事件并手动重新加载上一页:

window.onpopstate = function() {
    location.reload();
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 浏览网站后,AJAX页面load / history.pushState无法正常工作 - AJAX page load/history.pushState not working properly after navigating off website 如何通过history.pushState()更改URL时,如何使用原始URL刷新页面 - how to refresh the page with original URL when URL has been changed via history.pushState() History.pushState和页面刷新 - History.pushState and page refresh 在 JS 中使用 history.pushState 加载页面时后退按钮不起作用 - Back Button not work when load page using history.pushState in JS 使用history.pushState后检测浏览器后退按钮 - Detecting Browser Back Button after using history.pushState 在ReactJs中使用history.pushState()时,后退按钮不起作用 - Back button is not working when using history.pushState() in ReactJs 在使用`pushState`后浏览浏览器历史记录时,如何在我的Vue.js页面中执行状态更改? - How do perform state changes in my Vue.js page when navigating back through browser history after using `pushState`? 带后退和前进按钮的history.pushState - history.pushState with back and forward buttons 按下并调用history.back();之后; History.pushstate未实例化/不起作用 - After pressing back and calling history.back(); History.pushstate isn't instantiated / not working 页面上未检测到JavaScript(history.pushState) - No JavaScript being detected on page (history.pushState)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM