You are here: Reference > JavaScript > client-side > browser > methods > back (history, window)

back method (history, window)

Browser support:
Loads the previous page form the history list into the current window.
Works identically to the Back button of the browser application. If no previous page exists in the history, the back method has no effect. The window.back method is equivalent to the history.back method, but the window.back method is not supported by all commonly used browsers. Use the history.back for cross-browser functionality.
If you want to go forward in the window history list, use the forward method. The go(-1) can be used instead of the back method.
Note: in Internet Explorer, the back and forward buttons on the toolbar are not updated after the invocation of the back and forward methods.

Syntax:

object.back ( );
You can find the related objects in the Supported by objects section below.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the back method.
<head>
    <script type="text/javascript">
        function GoBack () {
            history.back ();
        }

        function GoForward () {
            history.forward ();
        }
    </script>
</head>
<body>
    Click on the following anchors first to add items to the history list.
    <br />
    <a href="#target1">First anchor</a>
    <a name="target1"></a>
    <br />
    <a href="#target2">Second anchor</a>
    <a name="target2"></a>
    <br /><br />
    Use these buttons to navigate in the history list:
    <button onclick="GoBack ();">go back in the history list</button>
    <button onclick="GoForward ();">go forward in the history list</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content