本文介绍了使用History.js时,如何检测单击的后退/前进按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在我的代码中结合使用jQuery和History.js(点击).

Im using History.js (click) with jQuery in my code.

通过ajax加载新内容时,我使用:

When loading new content via ajax i use:

History.pushState({my:stateobject},"newtitle","supernewurl");

这似乎可行,因为在浏览器中更新了URL.

This seems to work since the URL is updated in the browser.

但是,无论何时按下后退或前进按钮,我都无法将代码连接起来.哪个方法/事件用于此?

However, I don't get it where I can hook up my code whenever a back or forward button is pressed. Which method/event is used for this?

推荐答案

您需要将事件处理程序绑定到statechange事件,如下所示:

You need to bind an event handler to the statechange event, like this:

$(window).bind('statechange',function(){
// Do something, inspect History.getState() to decide what
})

History.js附带有完整的javascript代码段,可用于完全"ajaxify"网站: https://github.com/browserstate/ajaxify

There is a complete javascript snippet that comes with History.js, which can be used to 'ajaxify' a site completely: https://github.com/browserstate/ajaxify

看看那里以获得更多灵感.

Take a look there for more inspiration.

这篇关于使用History.js时,如何检测单击的后退/前进按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:37