[問題] 如何在popstate事件中取得「上一頁」的URL?

作者: freebug (Freebug)   2016-05-17 20:36:30
Here's a simple example of pushState and popstate event:
<button id="example_btn">Click me</button>
<script>
$("#example_btn").click(function(){
history.pushState(
{
'url' : "example.htm"
}, null, "example.htm");
});
$(window).bind('popstate', function (event) {
if (event.originalEvent.state) {
console.log(event.originalEvent.state.url);
}
});
</script>
When triggering the popstate event, it shows the url of the current page.
My question is:
How can I get the url of the previous page when triggering the popstate event
in this case?
P.S. I have tried document.referrer but it didn't show anything.
作者: mrbigmouth (大嘴先生)   2016-05-18 09:58:00
store url in local storage everytime step in page?you can't access history forward data
作者: aa06697 (todo se andarà)   2016-05-18 19:39:00
store in cookie

Links booklink

Contact Us: admin [ a t ] ucptt.com