kokeksibir
kokeksibir

Reputation: 1745

pushState scrambles browser history

In the test scenario I have two pages pageA and pageB.

In the first step a button triggers window.history.pushState call and in the address bar address of pageB is shown.

In the second step browser's address bar is used to make request for pageB. Browser renders content of pageB. In the address bar address of pageB is shown.

In the last step browser's back button is used to return back pageA. In the address bar address of pageA is shown. However browser displays content of pageB where I was expecting to see content of pageA.

I know I am doing something wrong. Even I have no clue how to describe this behaviour. Do you have any suggestions?

Here you can find demo in jsFiddle: http://jsfiddle.net/HqECT/3/show/

You may see the implementation: http://jsfiddle.net/HqECT/3/

Note: Test is run in Chrome v30.0.1599.101

Upvotes: 1

Views: 127

Answers (1)

Quentin
Quentin

Reputation: 943537

You need to listen for a popstate event. The event object will have a state property containing whatever data you put into the history when you called pushState. If you put the right data in it, you can use that to restore the page to the state for the old URL.

Upvotes: 2

Related Questions