You are here: Reference > JavaScript > client-side > HTML DOM > methods > replace (location)

replace method (location)

Browser support:
Removes the URL of the current document from the document history and loads the document at the specified URL into the current window.
This method is similar to the assign method, but the assign method does not remove the URL of the current document from the document history. After calling the replace method, the Back button cannot be used to navigate back to the original document, unlike in case of the assign method.

Syntax:

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

Parameters:

URL
Required. String that specifies the location of the document to load.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the replace method:
Code
newLocation.htm
<head>
    <script type="text/javascript">
        function ReplacePage () {
            window.location.replace ("newLocation.htm");
        }
    </script>
</head>
<body>
    <button onclick="ReplacePage ();">Replace the document!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content