History.go()

The 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 the delta parameter.

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

Syntax

window.history.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().

Examples

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

window.history.go(-1)

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

window.history.go(1)

To move forward two pages:

window.history.go(2);

To move backwards by two pages:

window.history.go(-2);

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

window.history.go();
window.history.go(0);

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'History' in that specification.
Living Standard No change from HTML5.
HTML5
The definition of 'History' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
goChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support 10Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also