window.history object can be used to manipulate a browser’s session history. Session history is localized to each specific browser tab. This means that we can also traverse between pages stored in a tab’s
To go back one page:
Both methods navigate to the previous page stored in the session history, but
history.go() can be used to go backward or forward any number of pages specified as the parameter if they exist within the session history’s range.
history.go(1) will both go forward one page and
history.go(0) will reload the current page.
To finish off the creation of a back button that acts like a browser’s native back button, we can write it like this: