Here is a simple example of a pushState and popstate :
<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 the popstate event is popstate , the URL of the current page is displayed.
My question is:
How can I get the URL of the previous page when the popstate event popstate in this case?
PS I tried document.referrer but didn't show anything.
source share