码迷,mamicode.com
首页 > Web开发 > 详细

html5的pushState 无刷新, 前进后退等

时间:2015-10-09 18:09:16      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

使用到的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地址,不能跨域。

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。

 

html5的pushState 无刷新, 前进后退等

标签:

原文地址:http://www.cnblogs.com/jingwensophie/p/4864600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!