开发者

What is the difference between location.replace() and location.assign() in JavaScript?

开发者 https://www.devze.com 2023-03-26 13:07 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号