Twilite
Twilite

Reputation: 873

Store data local to a specific instance of a page in a jQuery Mobile multi-page application

I have a jQuery Mobile multi-page application, that allows the user to navigate between pages using links or the browser back button.

I'd like to store some data or a flag in a specific page instance and read it again when the user navigates back to that page. The data should be local to the specific instance in the browser history stack and not available in other instances, like if the user navigates to the page again, going forward through links.

How would I store such data, or get a reference to instance of the page?

Ideally it would be something like $.mobile.uniqueActivePageInstance.data("attribute", "value")

Upvotes: 0

Views: 36

Answers (1)

Twilite
Twilite

Reputation: 873

I used the history state of the current element of the history stack to store the data:

Write:

history.replaceState($.extend(history.state, {myData: myDataObjectOrString}));

Read:

history.state.myData;

Upvotes: 1

Related Questions