window.location
adds an item to your history in that you can (or should be able to) click "Back" and go back to the current page.
(window.location
将一个项目添加到您的历史记录中,您可以(或应该能够)单击“返回”并返回当前页面。)
window.location.replace
replaces the current history item so you can't go back to it.
(window.location.replace
替换当前的历史记录项,因此您无法返回它。)
See window.location
:
(请参阅window.location
:)
assign(url)
: Load the document at the provided URL.
(assign(url)
:在提供的URL处加载文档。)
replace(url)
:Replace the current document with the one at the provided URL.
(replace(url)
:将当前文档替换为提供的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.(与assign()
方法的不同之处在于,在使用replace()
,当前页面将不会保存在会话历史记录中,这意味着用户将无法使用“后退”按钮导航到该页面。)
Oh and generally speaking:
(哦,一般来说:)
window.location.href = url;
is favoured over:
(受到青睐:)
window.location = url;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…