History go() Method
Example
Click on the button to go back two pages:
<button onclick="goBack()">Go Back 2 Pages</button>
<script>
function goBack() {
window.history.go(-2);
}
</script>
The output of the code above will be:
More "Try it Yourself" examples below.
Definition and Usage
The go() method loads a specific URL from the history list.
Tip: You can also use the back() or forward() method to load the previous or next URL in the history list.
Browser Support
Method | |||||
---|---|---|---|---|---|
go() | Yes | Yes | Yes | Yes | Yes |
Syntax
history.go(number|URL)
Parameter Values
Parameter | Description |
---|---|
number|URL | Required. The parameter can either be a number which goes to the URL within the specific position (-1 goes back one page, 1 goes forward one page), or a string. The string must be a partial or full URL, and the function will go to the first URL that matches the string. |
Technical Details
Return Value: | No return value |
---|
More Examples
Example
Go forward one page (This example will not work if the next page does not exist in the history list):
window.history.go(1);
Try it Yourself »
❮ History Object