English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript History go() Method

HTML History Object

go()method to load a specific URL from the history list.

If you know the specific page number or URL of the page to be loaded from the history record, usehistory.back()andhistory.forward()The method is a better choice.

Syntax:

history.go(number|URL)
<button onclick="history.go(-2);">Go 2 pages back</button>
Test and See‹/›

The following output will be displayed by the above code:

Browser Compatibility

All browsers fully support the go() method:

Method
history.go()YesYesYesYesYes

Parameter Value

ParameterDescription
number|URLThe parameter can be a number to navigate to a URL at a specific position (-1Go Back One Page,1Go Back One Page) or a string. The string must be a partial or complete URL, and the function will navigate to the first URL that matches the string.

Technical Details

Return Value:None

More Examples

Go Forward One Page (This example does not work if there is no next page in the history record list):

<button onclick="history.go(1);">Load the Next URL</button>
Test and See‹/›

Related References

History Record Reference:history.forward() Method

History Record Reference:history.back() Method

HTML History Object