Window history.go()

Example

Create a button to go back two pages:

<button onclick="history.go(-2)">Go Back 2 Pages</button>

The output of the code above will be:

Click on Go Back to see how it works.
(Will only work if the previous pages exist in your history list)

Try it Yourself »

Description

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

The history.go() method only works if the page exist in the history list.

Note

history.go(0) reloads the page.

history.go(-1) is the same as history.back().

history.go(1) is the same as history.forward().

See Also:

The history.back() Method

The history.forward() Method

The history.length Property


Syntax

history.go(number)

Parameters

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

Return Value

NONE

Browser Support

history.go() is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.