javascriptbrowser-history

Access the history state of the previous page when a user clicks 'back'


Is there a way using JS of accessing the history state of the previous page when a user clicks the 'back' button?


Solution

  • Unfortunately you're not allowed to read previous or next states. All you can do is reading current state, using history.state.

    But if it all happens on the same page without reloads, why don't you save data on you own stack. You can use array for this - just save the same data to array and new state.