![](/img/trans.png)
[英]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.