为Ajax应用程序启用back / fwd键事件 [英] Enabling back/fwd key events for an Ajax Application

查看:229
本文介绍了为Ajax应用程序启用back / fwd键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个适用于AJAX的应用程序。但是我想要有导航功能。为了欺骗网址,我正在更改location.hash,以生成网址。但是,如果我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆