user623520
user623520

Reputation:

what is the state object passed to history.pushState and what does it do?

What is the stateObj passed to history.pushState and what does it do?

For example, history.pushState(stateObj, title, url);

Upvotes: 12

Views: 4586

Answers (1)

s4y
s4y

Reputation: 51685

The state object, as defined by the spec, is any object that you, the author, want to associate with that state:

Pages can add state objects between their entry in the session history and the next ("forward") entry. These are then returned to the script when the user (or script) goes back in the history

The MDN has a more-practical (Firefox-specific) definition:

The state object can be anything that you can pass to JSON.stringify. Because Firefox saves state objects to the user's disk so they can be restored after the user restarts her browser, we impose a size limit of 640k characters on the JSON representation of a state object.

Upvotes: 8

Related Questions