Location replace() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

The replace() method replaces the current document with a new one by passing URL.

replace() removes the URL of the current document from the document history, and it is not possible to use the "back" button to navigate back to the original document.

Parameter Values

Parameter Type Description
newURLString Required. URL of the page to navigate to

Return Value

No return value

The following code shows how to Replace the current document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Replace document</button>

<script>
function myFunction() {//from w  w w . j a  v  a2 s  . com
    location.replace("http://www.java2s.com")
}
</script>

</body>
</html>

Related Tutorials