window.location.assign()和window.location.replace()之间的区别 [英] Difference between window.location.assign() and window.location.replace()

查看:182
本文介绍了window.location.assign()和window.location.replace()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

window.location.assign() window.location.replace()之间有什么区别,当两者都重定向到新页面时?

What is the difference between window.location.assign() and window.location.replace(), when both redirect to a new page?

推荐答案

使用 window.location.assign(url) 只会导致加载新文档。使用 window.location.replace(url)将替换当前文档,并将当前历史记录替换为该URL,以便您无法返回上一个文档已加载。

Using window.location.assign("url") will just cause a new document to load. Using window.location.replace("url") will replace the current document and replace the current History with that URL making it so you can't go back to the previous document loaded.

参考: http://www.exforsys.com/tutorials/javascript/javascript-location-object.html

这篇关于window.location.assign()和window.location.replace()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆