[英]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.