Window history.go() method

Definition and usage

history.go() The method loads a URL (page) from the history list.

history.go() The method is only valid when the page exists in the history list.

Comment

history.go(0) Reload the page.

history.go(-1) With history.back() Same.

history.go(1) With history.forward() Same.

See also:

history.back() method

history.forward() method

history.length method

Example

Create a button to go back two pages:

<button onclick="history.go(-2)">Go back two pages</button>

The output of the above code will be:

Click to return to see how it works.

(Only valid when there are previous pages in your history list)

Try it yourself

Syntax

history.go(number)

Parameter

Parameter Description
number Required. Negative values go back. Positive values go forward.

Return value

None.

Browser support

All browsers support history.go():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support