window.history allows limited access to the previously-visited pages in the same browser session.

For example, you can see how many pages the user has visited before coming to your page. You cannot see the actual URLs though for privacy reasons this doesn't work.

window.history.length //output:5

To navigate back and forth through the user's session as if the user had clicked the Back/Forward browser buttons.


To skip pages back and forth with history.go(). This is same as calling history.back():

history.go(-2); //Two pages back
history.go(0); //Reload the current page
History Object Properties
lengthReturns the number of URLs in the history list
History Object Methods
back()Loads the previous URL in the history list
forward()Loads the next URL in the history list
go()Loads a specific URL from the history list
Related Tutorial
Follow Us #
Contents +