简体   繁体   English

单击浏览器的后退按钮时,应用新URL不会自动加载页面

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

相关问题 单击浏览器上的后退按钮时如何加载确切的页面? - How to load the exact page when clicking back button on browser? 使用 Ajax 加载页面时,返回按钮不起作用 - When load page with Ajax, the go back button doesn't works 单击浏览器的后退按钮时重定向到特定页面 - redirecting to a specific page when clicking browser's back button 单击浏览器后退按钮时如何保持在同一页面上 - How to stay on the same page when clicking the browser back button Python selenium - 单击 javascript 链接不会加载新页面,但会显示 url - Python selenium- Clicking a javascript link doesn't load the new page but shows the url 付款后在浏览器中单击后退按钮可返回到其他页面 - Return to different page when clicking back button in browser after payment firefox浏览器的后退按钮无法刷新页面 - firefox browser back button doesn't refresh the page 单击浏览器后退按钮时,将用户带回上一页滚动到的位置 - Take User Back to Where They Scrolled to on previous page when clicking Browser Back Button 单击浏览器的“后退”按钮时,返回上一页的上一个位置 - Go Back to the Previous Location on Previous Page when Clicking Browser Back Button 将内容加载到iframe中后,浏览器后退按钮不起作用 - Browser back button doesn't work when content is loaded into an iframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM