This little History API demo hooks in to the browser button. We ran it using the the Firefox Developer Console. The demo does three things:
- Adds an
onpopstate = (e) => console.log(e.state)event handler.
history.pushState(state, title)three times.
When we then clicked the browser's back button three times.
- the current page did not change,
- the url did not change, and
- the event handler surfaced the history state.
This is a handy way to let users navigate (partial) page changes with the browser's back/forward buttons. This is important, because most users don't have clue about whether a page change was partial or not.