Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Location replace() method

Location replace() method

Location Object Reference Location object


Definition and Usage

The replace() method can replace the current document with a new document.

Syntax

location.replace(

newURL

)


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the replace() method


Example

Example

Use the replace() method to replace the current document:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

<

script

function replaceDoc(){ window.location.replace("https://www.runoob.com") }

script

head

<body>
<input type="button" value=">

Load a new document to replace the current page

"

onclick

=

"

replaceDoc()

"

body

html

Try it »


Location Object Reference Location object