Javascript Browser Location assign() Method

Introduction

Load a new document:

location.assign("https://www.java2s.com");

View in separate window

<!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



PreviousNext

Related