pushState与replaceState区别

history.pushState(state, title, url)


 

将当前URL和history.state加入到history中,并用新的state和URL替换当前。不会造成页面刷新。

state:与要跳转到的URL对应的状态信息。

title:可以不传

url:要跳转到的URL地址,不能跨域。

history.replaceState(state, title, url)


 

用新的state和URL替换当前。不会造成页面刷新。

state:与要跳转到的URL对应的状态信息。

title:可以不传

url:要跳转到的URL地址,不能跨域。


两者看似没有区别,其实区别很大的,pushState是添加历史记录的,而replaceState是不添加的。

posted @ 2015-12-25 18:30  黎明の破晓  阅读(1993)  评论(0编辑  收藏  举报