且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

window.location.href,window.location.replace和window.location.assign之间的区别

更新时间:2022-02-14 23:21:30

这些做同样的事情:

window.location.assign(url);
window.location = url;
window.location.href = url;

他们只需导航到新的URL。另一方面,替换方法导航到URL,而不向历史记录添加新记录。

They simply navigate to the new URL. The replace method on the other hand navigates to the URL without adding a new record to the history.

所以,你在这些形式中阅读的内容是不正确的。 $ c>分配方法会在历史记录中添加新记录。

So, what you have read in those many forms is not correct. The assign method does add a new record to the history.

参考: http://developer.mozilla.org/en/window.location