[英]HTML5 history: how can I see the URL that was popped (ie, the page we were on when we hit the back button)
I am using the HTML5 history API 我正在使用HTML5历史记录API
I notice that if: 我注意到,如果:
The event handler for window.onpopstate() returns the state for /first, as documented. 如前所述,window.onpopstate()的事件处理程序返回/ first的状态。
In order to transition from /second to /first, I would like to see the URL that was popped - ie, /second in this case . 为了从/ second过渡到/ first, 我想查看弹出的URL,即本例中的/ second 。 What's the best way of doing that?
最好的方法是什么?
In lieu of a proper answer, I've implemented the following workaround: 代替正确的答案,我实现了以下解决方法:
data-urlhack
attribute on the <body>
element when a page is loaded <body>
元素上使用data-urlhack
属性 onpopstate()
handler, checking the value of this attribute so I can transition from this page (where the back button was hit) to the page the back button has sent us to. onpopstate()
处理程序中,检查此属性的值,以便我可以从此页面(单击后退按钮的位置)过渡到后退按钮将我们发送到的页面。 Also ensure that pages loaded in onpopstate()
don't try and push use pushState()
themselves. 还要确保加载到
onpopstate()
中的页面不要尝试自己推送使用pushState()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.