W3cubDocs

/Web APIs

History: go() method

The History.go() method loads a specific page from the session history. You can use it to move forwards and backwards through the history depending on the value of a parameter.

This method is asynchronous. Add a listener for the popstate event in order to determine when the navigation has completed.

Syntax

js

go()
go(delta)

Parameters

delta Optional

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 and history.go(-2) moves back two pages. If no value is passed or if delta equals 0, it has the same result as calling location.reload().

Return value

None (undefined).

Examples

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

js

history.go(-1);

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

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
go 1 12 1 10 ≤12.1 1 4.4 18 4 ≤12.1 1 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/History/go