这里的pushState
和popstate
事件的一个简单的例子:如何在触发popstate事件时获取上一页的URL?
<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>
当触发事件popstate
,它显示当前页面的URL。
我的问题是:
我怎么能在这种情况下触发popstate
事件时,你得到以前页面的网址是什么?
P.S.我试过document.referrer
但它没有显示任何东西。