Load a new document:
location.assign("https://www.java2s.com");
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Load new document</button> <script> function myFunction() {/* w w w . j a va 2s. c om*/ location.assign("https://www.java2s.com"); } </script> </body> </html>
The assign()
method loads a new document.
location.assign(URL);
Parameter Values
Parameter | Type | Description |
---|---|---|
URL | String | Required. Specifies the URL of the page to navigate to |