The JavaScript History object is an object which is accessible through the history property of a window object. It exposes useful methods and properties that let you move back and forth through the user’s history.

History Object Properties

The History object has a valuable property that you can use to determine the number of items in the window’s history. We can use the length property. Internet Explorer and Opera begin at 0, while Chrome, Safari, and Firefox begin at 1.

Example

History Object Methods

The History object has a valuable property that you can use to determine the number of items in the window’s history. We can use the length property. Internet Explorer and Opera begin at 0, while Chrome, Safari, and Firefox begin at 1.

The back() and forward() methods are identical except one is used to go back while the other is used to go forward from the items in the window history.

Back() Example

[Go Back!]

Go() Example

[Go Back Two Pages!]