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

看板Ajax作者 (Freebug)時間8年前 (2016/05/17 20:36), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
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. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 173.238.132.250 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1463488594.A.1B0.html

05/18 09:58, , 1F
store url in local storage everytime step in page?
05/18 09:58, 1F

05/18 10:00, , 2F
you can't access history forward data
05/18 10:00, 2F

05/18 19:39, , 3F
store in cookie
05/18 19:39, 3F
文章代碼(AID): #1NEn1I6m (Ajax)
文章代碼(AID): #1NEn1I6m (Ajax)