History Object

History Object

The History Object contains the URLs that the user has visited (in the browser window).

The History Object is part of the window object and can be accessed through the window.history property.

Note:There is no publicly available standard for the History Object, but all browsers support this object.

Properties of History Object

Property Description
length Return the number of URLs in the browser history list.

Methods of History Object

Method Description
back() Load the previous URL from the history list.
forward() Load the next URL from the history list.
go() Load a specific page from the history list.

Description of History Object

The History Object was originally designed to represent the browser history of the window. However, due to privacy reasons, the History Object no longer allows scripts to access the actual URLs that have been visited. The only function that remains in use is back()forward() and go() Method.

Example

The operation performed by the following line of code is the same as that performed by clicking the back button:

history.back()

The operation performed by the following line of code is the same as that performed by clicking the back button twice:

history.go(-2)