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:

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

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

The output of the code above will be:


Try it yourself »

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


Examples

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