JavaScript History API
- Previous Page API Geolocation
- Next Page API MediaQueryList
Window History Object
The History object contains the URLs visited by the user (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:
Instance
let length = window.history.length;
let length = history.length;
Properties and methods of History object
Property/Method | 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 history of navigation. 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 API Geolocation
- Next Page API MediaQueryList