静文sophie

导航

 

使用到的api

history.state

 当前URL下对应的状态信息。

  如果当前URL不是通过pushState或者replaceState产生的,那么history.state是null。

history.pushState(state, title, url)

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

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

  title:标题

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

history.replaceState()

  history.replaceState() 用起来很像pushState(),

  除了replaceState()是用来修改当前的history实体而不是创建一个新的。

     你需要对某些用户行为作反应而更新一个state对象或者当前history实体时,可以使用它来更新state对象或者当前history实体的url。

window.onpopstate

history.go和history.back(包括用户按浏览器历史前进后退按钮)触发,并且页面无刷的时候(由于使用pushState修改了history)会触发popstate事件,事件发生时浏览器会从history中取出URL和对应的state对象替换当前的URL和history.state。通过event.state也可以获取history.state。

 

posted on 2015-10-09 17:28  静文sophie  阅读(342)  评论(0编辑  收藏  举报