Search code examples
javascriptbrowser-history

Restore original page when navigating back after history.pushState


I'm using history.pushState to create a 'fake' results page after the user submits a form. However, when I navigate back, the visible page stays the same. What is an easy way to get the original page - unmodified by javascript, but with the form filled out - after pressing back?


Solution

  • You need to watch the current address for changes and react to it yourself.

    See this example: https://developer.mozilla.org/en/DOM/window.onpopstate

    Also have a look at the documentation:

    https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history/