Javascript Reference - Location assign() Method








The assign() method loads a new document.

Browser Support

assign Yes Yes Yes Yes Yes

Syntax

location.assign(URL)

Parameter Values

Parameter Type Description
URL String Required. Specifies the URL of the page to navigate to




Return Value

No return value

Example

The following code shows how to Load a new document.


<!DOCTYPE html>
<html>
<body>
<!--from w  w  w  . ja  va 2s.c  o  m-->
<button onclick="myFunction()">Load new document</button>

<script>
function myFunction() {
    location.assign("http://www.example.com");
}
</script>

</body>
</html>

The code above is rendered as follows: