Search code examples
javascripthtmlhtml5-history

History API - replaceState on a previous page?


Wondering if I can use the HTML5 history API's replaceState() method (or something similar) to change the state of a previously visited page (as opposed to the current page)?


Solution

  • After doing more research...

    Strictly speaking, you can't use replaceState() to change where back navigation will go to. However, you can listen to the popstate event and navigate accordingly.

    Additional documentation:

    Mozilla's guide to 'Manipulating the browser history'

    Mozilla's window.history documentation