Jquery 如何检查是否调用了后退按钮事件?

Jquery 如何检查是否调用了后退按钮事件?,jquery,browser-history,hashtag,Jquery,Browser History,Hashtag,我试图使一个网站完全支持ajax,但是我很难弄清楚如何支持历史。我使用jquery作为哈希更改库,如下所示: $(document).on('click','a',function(){ var url = $(this).attr('href'); $.ajax({ // AJAX Call and populate }); $.History.go(url); return false; }); $('input[type="submi

我试图使一个网站完全支持ajax,但是我很难弄清楚如何支持历史。我使用jquery作为哈希更改库,如下所示:

$(document).on('click','a',function(){
    var url = $(this).attr('href');
    $.ajax({
        // AJAX Call and populate
    });
    $.History.go(url);
    return false;
});
$('input[type="submit"]').livequery('click',function(event){
    $(this).closest("form").ajaxForm(get_pages_load_options);
    var url = $(this).closest("form").attr('action');
    $.History.go(url);
});
$('.get_pages').livequery('change',function(){
    $(this).closest("form").ajaxForm(get_pages_load_options);
    var url = $(this).closest("form").attr('action');
    $.History.go(url);
});
我还使用以下javascript作为书签:

function hash_process() {
    url = window.location.hash.replace('#', '');
    $.ajax({
        //AJAX Call and Populate
    });
}
if (window.location.hash) {
    hash_process();
}
然而,对于以上两个片段,我发现后退按钮不起作用,尤其是对于提交的表单。如果我添加以下代码,它只会给我默认页面,没有任何提交的信息,就像我从来没有提交过表单一样

window.onhashchange = hash_process;

有没有办法检查是否调用了后退按钮?任何想法都将不胜感激,谢谢

我找到了这个难题的答案。由于第二次调用是在我提交表单后引起的,因此我只在混合中添加了一个加法变量,如下所示:

ignore_hash = false;
function hash_process() {
    if (ignore_hash == false) {
        url = window.location.hash.replace('#', '');
        $.ajax({
            // AJAX Call & Populate
        });
    } else {
        ignore_hash = false;
    }
}
在检查之前启动的函数中,我将该变量添加到执行中:

$(document).on('click','a',function(){
    var url = $(this).attr('href');
    $.ajax({
        // AJAX Call & Populate
    });
    $.History.go(url);
    ignore_hash = true;
    return false;
});

我找到了这个难题的答案。由于第二次调用是在我提交表单后引起的,因此我只在混合中添加了一个加法变量,如下所示:

ignore_hash = false;
function hash_process() {
    if (ignore_hash == false) {
        url = window.location.hash.replace('#', '');
        $.ajax({
            // AJAX Call & Populate
        });
    } else {
        ignore_hash = false;
    }
}
在检查之前启动的函数中,我将该变量添加到执行中:

$(document).on('click','a',function(){
    var url = $(this).attr('href');
    $.ajax({
        // AJAX Call & Populate
    });
    $.History.go(url);
    ignore_hash = true;
    return false;
});