Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. History
  4. go()

History: go() method

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⁩.

Thego() method of theHistory interface loads a specific page from thesession history. You can use it to move forwards and backwards through the historydepending on the value of a parameter.

This method isasynchronous. Add a listener for thepopstate event in order to determine when the navigation has completed.

Syntax

js
go()go(delta)

Parameters

deltaOptional

The position in the history to which you want to move, relative to the current page.A negative value moves backwards, a positive value moves forwards. So, for example,history.go(2) moves forward two pages andhistory.go(-2)moves back two pages. If no value is passed or ifdelta equals 0, it hasthe same result as callinglocation.reload().

Return value

None (undefined).

Exceptions

SecurityErrorDOMException

Thrown if the associated document is not fully active. Browsers also throttle navigations and may throw this error, generate a warning, or ignore the call if it's called too frequently.

Examples

To move back one page (the equivalent of callingback()):

js
history.go(-1);

To move forward a page, just like callingforward():

js
history.go(1);

To move forward two pages:

js
history.go(2);

To move backwards by two pages:

js
history.go(-2);

And finally, either of the following statements will reload the current page:

js
history.go();history.go(0);

Specifications

Specification
HTML
# dom-history-go-dev

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp