DOM:window.history
From MDC
Contents |
[edit] Summary
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).
[edit] Syntax
historyObj = window.history;
The obtained History object has the following methods:
| Method | Description | Return value |
|---|---|---|
history.back() |
Goes to the previous page in session history, the same action as when the user clicks the browser's Back button. Equivalent to |
No return value |
history.forward() |
Goes to the next page in session history, the same action as when the user clicks the browser's Forward button. Equivalent to |
No return value |
history.go(integerDelta) |
Loads a page from the session history, identified by its relative location to the current page, for example -1 for the previous page or 1 for the next page.When |
No return value |
The History object also has the following properties:
| Property | Type | Description |
|---|---|---|
length |
Integer | Read-only. Returns the number of elements in the session history, including the currently loaded page. For example, for a page loaded in a new tab this property will return |
current |
String | Returns the URL of the active item of the session history. This property is not available to web content and is not supported by other browsers. Use |
next |
String | Returns the URL of the next item in the session history This property is not available to web content and is not supported by other browsers. |
previous |
String | Returns the URL of the previous item in the session history This property is not available to web content and is not supported by other browsers. |
[edit] Example
history.back(); // equivalent to clicking back button
[edit] 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.
[edit] See also
[edit] Specification
DOM Level 0. Not part of any standard.