The Window.history
read-only property returns a reference to the History
object, which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in).
See Manipulating the browser history for examples and details. In particular, that article explains security features of the pushState()
and replaceState()
methods that you should be aware of before using them.
Example
history.back(); // equivalent to clicking back button
history.go(-1); // equivalent to history.back();
Notes
For top-level pages you can see the list of pages in the session history, accessible via the History
object, in the browser's dropdowns next to the back and forward buttons.
For security reasons the History
object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace()
method, which replaces the current item of the session history with the provided URL.
Specifications
Specification | Status | Comment |
HTML Living StandardThe definition of 'The History interface' in that specification. | Living Standard | |
HTML5The definition of 'The History interface' in that specification. | Recommendation |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
history
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 4 |
Opera
Full support 3 |
Safari
Full support 1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
Window.history by Mozilla Contributors is licensed under CC-BY-SA 2.5.