Javascript Reference - History go() Method








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

Browser Support

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 of a partial or full URL, and the function will go to the first URL that matches the string.




Return Value

No return value.

Example

The following code shows how to click on the button to go back two pages.


<!DOCTYPE html>
<html>
<head>
<script>
function goBack() {<!-- w w  w.  j a  v a2  s  . c  om-->
    window.history.go(-2)
}
</script>
</head>
<body>
<button onclick="goBack()">Go 2 pages back</button>
</body>
</html>

The code above is rendered as follows: