这两行有区别吗?
var url = "http://www.google.com/";
window.location = url;
window.location.replace(url);
最佳答案
window.location
将一个项目添加到您的历史记录中,您可以(或应该能够)单击“返回”并返回当前页面。
window.location.replace
替换当前历史记录项,因此您无法返回。
见 window.location
:
assign(url)
: Load the document at the provided URL.
replace(url)
:Replace the current document with the one at the provided URL. The difference from theassign()
method is that after usingreplace()
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.
哦,一般来说:
window.location.href = url;
被青睐:
window.location = url;
关于javascript - window.location= 和 window.location.replace() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1865837/