History go()Method
History Object
Definition and Usage
The go() method loads a specific page from the history list.
The parameter can be a number, which uses the relative position of the URL to be visited in the History URL list. (-1 goes back one page, 1 goes forward one page). Or it can be a string, which must be a partial or full URL. The function will match the first URL of the string.
Syntax
history.go(number|URL)
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the go() method.
Example
Example
Click to go back two pages:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function goBack(){
window.history.go(-2)
}
</script>
</head>
<body>
<input type="button" value="Go back 2 pages" onclick="goBack()">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function goBack(){
window.history.go(-2)
}
</script>
</head>
<body>
<input type="button" value="Go back 2 pages" onclick="goBack()">
</body>
</html>
The output of the above example:
Try it yourself »
History Object Other Extensions