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

assign method (location)

Browser support:
Overrides the location of the current document, so it effectively loads a new document.
This method performs the same action as assigning a new value to the location.href property.
The replace method is similar to the assign method, but it removes the URL of the current document from the document history when it loads the new document. 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.assign (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 assign method.
Code
newLocation.htm
<head>
    <script type="text/javascript">
        function LoadNewPage () {
            location.assign ("newLocation.htm");
        }
    </script>
</head>
<body>
    <button onclick="LoadNewPage ()">Load a new 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