location.replace
时间: 2023-09-08 15:10:27 浏览: 42
Location.replace() is a JavaScript method that replaces the current document with a new one by navigating to a new URL. It is similar to the location.href method but with one key difference - it does not create a new entry in the browser's history, which means that the user cannot use the back button to return to the previous page. Instead, it replaces the current entry in the history with the new URL.
The syntax for using this method is as follows:
```
location.replace(newUrl);
```
where `newUrl` is the URL of the new page you want to replace the current page with.
Here's an example of how to use the Location.replace() method:
```
function redirectToNewPage() {
location.replace("https://www.example.com/newpage.html");
}
```
When this function is called, it will replace the current page with the new page specified in the URL.