码迷,mamicode.com
首页 > 其他好文 > 详细

history(路由控制)

时间:2017-10-18 11:48:38      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:cat   历史记录   cti   替换   UI   for   out   doc   执行   

 

关键对象和方法

history.pushState();   //历史记录 新增一条链接,并改变当前URL  ,页面无刷新

history.replaceState(); //替换当前URL,同时更新历史记录,  页面无刷新

 

事件

onpopstate{

  //这三个方法会触发 onpopstate事件

  history.forward()  //向前翻一页

  history.back()    //向后翻一页

  history.go()  //指定翻页

}

setTimeout(()=>history.pushState({page:1,uid:2200},‘这个参数没什么用‘,‘home.html‘),2000)

setTimeout(()=>history.pushState({page:2,cookie:303030303},‘这个还是没什么用‘,‘about.html‘),4000)



//执行回退 触发 onpopstate事件
setTimeout(()=>history.back(),6000);

window.onpopstate = function(event){
  console.log(document.location)
  console.log(event.state) //返回你定义的当前页面的第一个参数对象{page:1,uid:2200}
}


 

history(路由控制)

标签:cat   历史记录   cti   替换   UI   for   out   doc   执行   

原文地址:http://www.cnblogs.com/hnshi/p/7685834.html

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