Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. History

History

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheHistory interface of theHistory API allows manipulation of the browsersession history, that is the pages visited in the tab or frame that the current page is loaded in.

There is only one instance ofhistory (It is asingleton.) accessible via the global objecthistory.

Note:This interface is only available on the main thread (Window). It cannot be accessed inWorker orWorklet contexts.

Instance properties

TheHistory interface doesn't inherit any property.

lengthRead only

Returns anInteger representing 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 returns1.

scrollRestoration

Allows web applications to explicitly set default scroll restoration behavior on history navigation. This property can be eitherauto ormanual.

stateRead only

Returns anany value representing the state at the top of the history stack. This is a way to look at the state without having to wait for apopstate event.

Instance methods

TheHistoryinterface doesn't inherit any methods.

back()

This asynchronous method goes to the previous page in session history, the same action as when the user clicks the browser'sBack button. Equivalent tohistory.go(-1).

Calling this method to go back beyond the first page in the session history has no effect and doesn't raise an exception.

forward()

This asynchronous method goes to the next page in session history, the same action as when the user clicks the browser'sForward button; this is equivalent tohistory.go(1).

Calling this method to go forward beyond the most recent page in the session history has no effect and doesn't raise an exception.

go()

Asynchronously loads a page from the session history, identified by its relative location to the current page, for example-1 for the previous page or1 for the next page. If you specify an out-of-bounds value (for instance, specifying-1 when there are no previously-visited pages in the session history), this method silently has no effect. Callinggo() without parameters or a value of0 reloads the current page.

pushState()

Pushes the given data onto the session history stack with the specified title (and, if provided, URL). The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized. Note that all browsers but Safari currently ignore thetitle parameter. For more information, seeWorking with the History API.

replaceState()

Updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized. Note that all browsers but Safari currently ignore thetitle parameter. For more information, seeWorking with the History API.

Specifications

Specification
HTML
# the-history-interface

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp