监听后退事件和hash变化

var detectBack = {
initialize: function() {
//监听hashchange事件
window.addEventListener('hashchange', function() {
//为当前导航页附加一个tag
this.history.replaceState('hasHash', '', '');


}, false);
window.addEventListener('popstate', function(e) {
if(e.state) {
//侦测是用户触发的后退操作, dosomething
//这里刷新当前url
this.location.reload();
}
}, false);
}
}

detectBack.initialize();


在张鑫旭的站上有看到一篇简单易懂的实例     http://www.zhangxinxu.com/wordpress/2013/06/html5-history-api-pushstate-replacestate-ajax/    很厉害

猜你喜欢

转载自blog.csdn.net/aydongzhiping/article/details/78329641