Javascript History Object provides the function to get the browser history information for the current browser window opened by the visitor. Javascript history object returns the previously visited web pages by the visitor for the current window of web browser initiated with single browser session. History object of Javascript consists of 1 property and 3 methods that return the value corresponding to the single browser window currently used by the client. Javascript runtime engine creates the history object that stores the list of URLs in the form of array visited by the user in single browser window.
Javascript History Object Property
length: length property of the javascript history object returns the number of items stored in the array collection of URLs visited by the user.
Javascript History Object Methods
go: go method of javascript history object takes types of parameters. You can pass -1 or 1 to go back to previous or go forward to next page in the history of web browser window. go method can perform the same functions as other methods of history object can do.
back: back method of javascript history object redirects to the previously visited page by user saved in the history of browser window.
forward: forward method of javascript history object redirects the page to the next page that the user was viewing. When user clicks the back button of web browser it stores the currently viewing URL in the history. If there is a button with forward method on the page opened after clicking the back button. Then by clicking on that forward button will redirect the user to the currently viewing URL previously stored into the browser history again.
Continue to next tutorial: Javascript History Length Property to learn how to get number of recently visited pages.