[英]When clicking back button of browser, the page doesn't load automatically by applying the new URL
Some background info: 一些背景信息:
for example, I load page with url1 then I used window.history.pushState()
to modify URL to be URL2 例如,我用url1加载页面然后我使用window.history.pushState()
将URL修改为URL2
I then click the "back" button, I noticed that the address line changes the URL to be URL1 but the page doesn't load to reflect the contents. 然后我单击“后退”按钮,我注意到地址行将URL更改为URL1,但页面未加载以反映内容。
What is the trick here? 这里的诀窍是什么? Thanks! 谢谢!
You need to listen for the window's popstate
event like this: 您需要像这样监听窗口的popstate
事件:
addEventListener('popstate', function() {
// code to be executed when back button is clicked
}, false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.