HTML DOM replace() 方法

定义和用法

replace() 方法可用一个新文档取代当前文档。

语法

  1. location.replace(newURL)

说明

replace() 方法不会在 History 对象中生成一个新的记录。当使用该方法时,新的 URL 将覆盖 History 对象中的当前记录。

实例

下面的例子将使用 replace() 方法来替换当前文档:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function replaceDoc()
  5. {
  6. window.location.replace("http://www.baidu.com")
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <input type="button" value="Replace document" onclick="replaceDoc()" />
  13.  
  14. </body>
  15. </html>