Location replace()Method
Location Object
Definition and Usage
The replace() method replaces the current document with a new document.
Syntax
location.replace(newURL)
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the replace() method.
Examples
Examples
Use the replace() method to replace the current document:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function replaceDoc(){
window.location.replace("https://www.example.com")
}
</script>
</head>
<body>
<input type="button" value="Load a new document to replace the current page" onclick="replaceDoc()">
</body>
</html>
Try it Yourself »
Location Object Other Extensions