Javascript History go function can perform both the functions as javascript history back and forward function can do. Javascript history go function accepts integer value or string value to perform the specific action according to the parameter passed. -1 value as a parameter passed to the history go function performs the history.back action and 1 as history.forward. Javascript history go function also accepts the string type value that can be used to pass the URL of the previous or next URL from the browser history. But URL string parameter is rarely used.

Syntax for Javascript History Go Function

history.go(number|[URL])

or

window.history.go(number|[URL])

history.go function of javascript can also be accessed using window object. You can pass -1 or 1 to the go function of history object or you can pass the URL of the previously visited page stored in the web browser history.

Examples of Javascript History Go Function

<html>
<head>
    <title>Javascript History Object Go Function</title>
</head>
<body>
    <input
        id="btnGo"
        type="button"
        value="Go"
        onclick="history.go(1);" />
    <input
        id="btnGo"
        type="button"
        value="Go"
        onclick="history.go(-1);" />
</body>
</html>

Above example shows the use of history.go function with two types of number values as -1 or 1.

history.go(-1) loads the previous URL from the history of web browser and history.go(1) loads the next URL saved in the web browser history collection.

Continue to next tutorial: Javascript Window History Object to get information about all JavaScript history object methods.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.