JavaScripture
Contribute via GitHub Feedback

History : Object

Represents the history of pages displayed to the user. Allows the webpage to manipulate the history by adding new pages or navigating between pages already in the history. Use the window.onpopstate event to listen to the user changing the page through the browser's back/forward buttons. See also Location.

Instance Properties

length : Number  

The number of items in the browser session's history.

Example:

Run

Results:

 

state : Object  

The data passed to pushState() or replaceState() for the current page.

Example:

Run

Results:

 

Instance Methods

back() : undefined

Navigates back one page in the session history. Equivalent to go(-1).

Example:

Run

Results:

 

forward() : undefined

Navigates forward one page in the session history. Equivalent to go(1).

Example:

Run

Results:

 

go([delta : Number]) : undefined

Navigates through the session history by the specified amount. If delta is not provided, go() acts the same as location.reload() and reloads the current page. See also back() and forward().

Example:

Run

Results:

 

pushState(state : Object, title : String, [url : String]) : undefined

Adds a new entry to the session history. state is available on the history.state property. title is applied to document.title. If url is specified, the location.href is changed to the provided value.

Example:

Run

Results:

 

replaceState(state : Object, title : String, [url : String]) : undefined

Replaces the current entry in the session history with the provided values. state is available on the history.state property. title is applied to document.title. If url is specified, the location.href is changed to the provided value.

Example:

Run

Results: