X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

History go() Method

History Object Reference History Object

Example

Click on the button to go back two pages:

<script>
function goBack() {
    window.history.go(-2)
}
</script>

<body>
<button onclick="goBack()">Go Back 2 Pages</button>
</body>

The output of the code above will be:


Try it yourself »


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

Internet Explorer Firefox Opera Google Chrome Safari

The go() method is supported in all major browsers.


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.

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 Reference History Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook