mikemaccana
mikemaccana

Reputation: 123420

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

I notice that if:

The event handler for window.onpopstate() returns the state for /first, as documented.

In order to transition from /second to /first, I would like to see the URL that was popped - ie, /second in this case. What's the best way of doing that?

Upvotes: 0

Views: 403

Answers (1)

mikemaccana
mikemaccana

Reputation: 123420

In lieu of a proper answer, I've implemented the following workaround:

  • Using a data-urlhack attribute on the <body> element when a page is loaded
  • In 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.

Also ensure that pages loaded in onpopstate() don't try and push use pushState() themselves.

Upvotes: 1

Related Questions