Joakim Johansson
Joakim Johansson

Reputation: 3194

Loading History.js state after back button from other page

I'm trying to use History.js to track the state of ui that has been manipulated with Javascript. The purpose is that users want to come back to the page (after visiting other pages in the system via links) in the state they left it in.

For this I bind the event for popstate like such:

History.Adapter.bind(window, 'popstate', function () {
    var History = window.History;
    var State = History.getState();
    LoadState(State, true);
});

Which works fine in most browsers while still navigating in the page, but only Chrome seems to trigger the event when going back to the page from another page. I've tried binding statechange as well, but it seems to trigger only on in-page navigation and not on "back-loading" a page.

Am I even correct in assuming there is a way to trigger an event when going back to a page? If so, how?

Upvotes: 3

Views: 1173

Answers (1)

Joakim Johansson
Joakim Johansson

Reputation: 3194

Found one solution to this problem, which is by declaring history.navigationMode = 'compatible'

This makes the ready-event trigger also when loading the page after going back to it from another page. From there on it's then possible to just retrieve the history object and load it as usual.

Upvotes: 1

Related Questions