766
The JavaScript history object is used to represent an array of URLs which are visited by the user.
It exposes some methods and properties that let you navigate back and forth through the user's history, and manipulate the contents of the history stack.
The history object is a window property, so it can be accessed like this:
window.history or history
Properties
Property | Description |
---|---|
length | returns the length of the history URLs. |
Methods
Method | Description |
---|---|
forward() | loads the next page. |
back() | loads the previous page. |
go() | loads the given page number. |
Examples
Here are some examples of the history object
history.back();//for previous page history.forward();//for next page history.go(2);//go forward 2 pages history.go(-2);//go back 2 pages