Location replace()Method

Location 对象参考手册Location Object

Definition and Usage

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

Syntax

location.replace(newURL)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 对象参考手册Location Object Other Extensions