What is the difference between location.replace() and location.assign() in JavaScript?
I want to know what is the difference between location.replace()
and location.assign()
.
I looked carefully but I didn't notice 开发者_如何学JAVAany difference between them!
location.replace()
goes to the page with the argument, replacing the current page in history.
location.assign()
goes to the page with the argument, adding a new item to the history.
https://developer.mozilla.org/en-US/docs/Web/API/Window/location
From MDN on replace()
:
Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.
https://developer.mozilla.org/En/Window.location
精彩评论