我在我的代码中使用jQuery和History.js(点击)。
当通过ajax加载新内容时,我使用以下代码:
History.pushState({my:stateobject},"newtitle","supernewurl");
看起来这个方法可以工作,因为浏览器中的URL已经更新。
然而,我不知道在哪里可以连接我的代码,每当用户按下返回或前进按钮时。哪种方法/事件可用于此?
我在我的代码中使用jQuery和History.js(点击)。
当通过ajax加载新内容时,我使用以下代码:
History.pushState({my:stateobject},"newtitle","supernewurl");
看起来这个方法可以工作,因为浏览器中的URL已经更新。
然而,我不知道在哪里可以连接我的代码,每当用户按下返回或前进按钮时。哪种方法/事件可用于此?
statechange
事件,如下所示:$(window).bind('statechange',function(){
// Do something, inspect History.getState() to decide what
})
History.js带有完整的JavaScript片段,可以用来完全“ajaxify”网站:https://github.com/browserstate/ajaxify
点击链接查看更多灵感。
History.Adapter.bind(window,'popstate',function(){ $modalContext.modal('close'); });
- chug2kwindow.history.pushState
、window.history.popState
和window.history.replaceState
方法,确保history
对象处于正确的状态。window.onpopstate = function(event) {
$(fellowModal).foundation('reveal', 'close');
};
我尝试了几种其他方法,但这是对我有效的。