You are here: Reference > JavaScript > client-side > browser > objects > history

history object

Browser support:
Provides access to the browser history that contains the URLs of visited pages.
Because of security restrictions, the URLs listed in the browser history are read-only, but it is allowed to navigate in the history with the back, forward or go methods.
If you want to load a new document, use the location object instead.

Syntax:

Properties that reference the object:
window.history
The base interface, through which you can add new functionalities to the history object, is the History interface.

Possible members:

Properties:
current
Returns the URL of the current document in the history array.
length
Returns the number of entries in the history list of the current browser window.
navigationMode
Sets or retrieves the navigation type in the history.
next
Returns the URL of the next document in the history array.
previous
Returns the URL of the previous document in the history array.
Methods:
back
Loads the previous page form the history list into the current window.
forward
Loads the next page form the history list into the current window.
go
Loads a page from the history list into the current window.

Example HTML code 1:

This example illustrates the use of the history object:
<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

Related pages:

External links:

User Contributed Comments

Post Content

Post Content