html5新特性:pushState,onpopstate
详见demo代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title></title> </head> <body> <button id="btn">按钮</button> <script> var btn=document.getElementById('btn'); var ind=0; var obj={ind:ind}; btn.onclick=function(){ obj.ind++; //参数一:obj供以后onpopstate使用(重要) //参数二:暂无其他意义 //参数三:浏览器地址栏历史地址(重要) history.pushState(obj,'ind','ind'+obj.ind); } window.onpopstate=function(ev){ //ev.state为pushState时传入的obj参数 if(ev.state){ document.title=ev.state.ind } } </script> </body> </html>