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
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 andhistory.go(-2)
moves back two pages. If no value is passed or ifdelta
equals 0, it has the same result as callinglocation.reload()
.
Examples
To move back one page (the equivalent of calling back()
):
history.go(-1)
To move forward a page, just like calling forward()
:
history.go(1)
To move forward two pages:
history.go(2);
To move backwards by two pages:
history.go(-2);
And, finally either of the following statements will reload the current page:
history.go(); history.go(0);
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'History.go()' in that specification. |
Living Standard | No change from HTML5. |
HTML5 The definition of 'History.go()' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
go | Chrome Full support Yes | Edge Full support 12 | Firefox Full support Yes | IE Full support 10 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support