Location assign()Method
Location Object
Definition and Usage
The assign() method loads a new document.
Syntax
location.assign(URL)
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the assign() method.
Example
Example
Use assign() to load a new document:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function newDoc(){
window.location.assign("http://www.example.com")
}
</script>
</head>
<body>
<input type="button" value="Load new document" onclick="newDoc()">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function newDoc(){
window.location.assign("http://www.example.com")
}
</script>
</head>
<body>
<input type="button" value="Load new document" onclick="newDoc()">
</body>
</html>
Try it Yourself »
Location Object Other Extensions