为 Ajax 应用程序启用 back/fwd 键事件 [英] Enabling back/fwd key events for an Ajax Application
本文介绍了为 Ajax 应用程序启用 back/fwd 键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在 AJAX 上工作的应用程序.但是我想在其中包含导航功能.为了欺骗 url,我正在更改 location.hash,以生成 URL.但是如果我使用 back/fwd,只有 url 改变,但页面不会重新加载.如何覆盖 hstory.back
以重新加载页面.
I have an application which works heavily on AJAX. However I want to have navigation functionalities in it. To spoof the url, I am changing the location.hash, to generate URL. But if I use back/fwd, only the url changes, but page wont reload. How can I override the hstory.back
to reload the page.
推荐答案
我不知道除了连续轮询之外还有什么其他方法可以实现这种行为.实现可能如下所示:
I don't know of any other way than continuous polling to implement this behaviour. An implementation might look like this:
var lastHash = '';
function pollHash() {
if(lastHash !== location.hash) {
lastHash = location.hash;
// hash has changed, so do stuff:
alert(lastHash);
}
}
setInterval(pollHash, 100);
这篇关于为 Ajax 应用程序启用 back/fwd 键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文