JavaScript 无刷新修改浏览器URL地址栏

//发现地址栏已改为:newUrl
var
stateObject = {}; var title = "Wow Title"; var newUrl = "/my/awesome/url"; history.pushState(stateObject,title,newUrl);

 

复制代码
//
for
(i=0;i<5;i++){ var stateObject = {id: i}; var title = "Wow Title "+i; var newUrl = "/my/awesome/url/"+i; history.pushState(stateObject,title,newUrl); alert(i); } window.addEventListener('popstate', function(event) { readState(event.state); }); function readState(data){ alert(data.id); }
复制代码

 

 

 

 

参考:http://www.jquerycn.cn/a_10532

 

posted @   James2019  阅读(6912)  评论(0编辑  收藏  举报

点击右上角即可分享
微信分享提示