语法:
location.replace(URL)
参数:此方法接受单个参数URL。URL是需要替换旧页面的其他页面的引用。
说明:replace() 方法不会在 History 对象中生成一个新的记录。当使用该方法时,新的 URL 将覆盖 History 对象中的当前记录。
示例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h2>Replace方法</h2> <button onclick="Replace()">重定向</button> <script> //Replace function that replace the current page. function Replace() { location.replace("https://www.0133.cn/") } </script> </body> </html>
效果图:
以上就是JavaScript的replace()方法有什么用?的详细内容,更多请关注0133技术站其它相关文章!