history.js 一个无刷新就可改变浏览器栏地址的插件(不依赖jquery)
简介
window.history.back();
window.history.forward();
window.history.go(-1);
window.history.go(1);
var currentState = history.state;
var stateObj = { foo: "bar" };
window.history.pushState(stateObj, "page 2", "bar.html");
代码示例
(function(window,undefined){ // Bind to StateChange Event History.Adapter.bind(window,‘statechange‘,function(){ // Note: We are using statechange instead of popstate var State = History.getState(); // Note: We are using History.getState() instead of event.state }); // Change our States History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1" History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2" History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3" History.pushState(null, null, "?state=4"); // logs {}, ‘‘, "?state=4" History.back(); // logs {state:3}, "State 3", "?state=3" History.back(); // logs {state:1}, "State 1", "?state=1" History.back(); // logs {}, "Home Page", "?" History.go(2); // logs {state:3}, "State 3", "?state=3" })(window);
效果
www.mysite.com www.mysite.com/?state=1 www.mysite.com/?state=2 www.mysite.com/?state=3 www.mysite.com/?state=4 www.mysite.com/?state=3 www.mysite.com/?state=1 www.mysite.com www.mysite.com/?state=3
www.mysite.com www.mysite.com/#?state=1&_suid=1 www.mysite.com/#?state=2&_suid=2 www.mysite.com/#?state=3&_suid=3 www.mysite.com/#?state=4 www.mysite.com/#?state=3&_suid=3 www.mysite.com/#?state=1&_suid=1 www.mysite.com www.mysite.com/#?state=3&_suid=3
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。