window.onpopstate is not working; nothing happens when I navigate back to page
问题 I'm trying to add window.onpopstate on one of the pages on my site, but nothing is happening. I put this script on the page: <script type="text/javascript"> window.addEventListener('popstate', function(event) { if (event.state) { alert(event.state); } }, false); </script> I have also tried: <script type="text/javascript"> window.onpopstate = function() { alert("popped!"); } </script> However, I don't get any alerts when I navigate back to the page. 回答1: You get a popstate event only if you