Window History Object
- Previous Page frames
- Next Page getComputedStyle()
- Go Up One Level Window Object
Window History Object
The History object contains the URLs that the user has visited (in the browser window).
The History object is a property of the window object.
The History object can be accessed in the following way:
window.history
or simply history
:
Example
let length = window.history.length;
let length = history.length;
Properties and methods of History object
Properties/Methods | Description |
---|---|
back() | Loads the previous URL (page) in the history list. |
forward() | Loads the next URL (page) in the history list. |
go() | Loads a specific URL (page) from the history list. |
length | Returns the number of URLs (pages) in the history list. |
Description of History object
The History object was originally designed to represent the browser's navigation history. 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)
- Previous Page frames
- Next Page getComputedStyle()
- Go Up One Level Window Object