[英]Difference between window.location.href, window.location.replace and window.location.assign
[英]Difference between window.location.assign() and window.location.replace()
window.location.assign()
和window.location.replace()
都重定向到新頁面時有什么區別?
使用window.location.assign("url")
只會導致加載新文檔。 使用window.location.replace("url")
將替換當前文檔並用該 URL 替換當前歷史記錄,這樣您就無法返回到上一個加載的文檔。
參考: http ://www.exforsys.com/tutorials/javascript/javascript-location-object.html
不同之處在於如何處理歷史。 “替換”不會給你歷史,“分配”會。
與
assign()
方法的不同之處在於,在使用replace()
之后,當前頁面將不會保存在會話歷史記錄中,這意味着用戶將無法使用“后退”按鈕導航到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.