Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用History.js back按钮不会';不行?_Javascript_Ajax_History.js - Fatal编程技术网

Javascript 使用History.js back按钮不会';不行?

Javascript 使用History.js back按钮不会';不行?,javascript,ajax,history.js,Javascript,Ajax,History.js,我在这里使用History.js 这就是我目前拥有的: var History = window.History; if (History.enabled) { // set initial state for first page that is loaded var State = History.getState(); History.pushState({urlPath: window.location.pathname},

我在这里使用History.js

这就是我目前拥有的:

    var History = window.History;
    if (History.enabled) {
        // set initial state for first page that is loaded
        var State = History.getState();
        History.pushState({urlPath: window.location.pathname}, $("title").text(), State.urlPath);
    } 
    else {
        return false;
    }

    // content update and back/forward button handler
    History.Adapter.bind(window, 'statechange', function(){
        var s = History.getState();
        History.log(s.data, s.title, s.url);

        // update view based on load type
        OnLoadPageByURL(s.data.urlPath);
    });

    // navigation link handler(s)
    $('body').on('click', 'a', function(e){
        e.preventDefault();

        var load = $(e.currentTarget).data('load');
        var urlPath = $(this).attr('href');
        var title = $(this).text();

        History.pushState({ load: load, urlPath: urlPath }, title, urlPath);
    });

一切似乎都正常工作,但“后退”按钮似乎工作不正常?我做错了什么?

请您提供有关
OnLoadPageByURL(s.data.urlPath)的详细信息?哦,对不起。我实际上解决了这个问题。上面的代码是完美的。我在其他地方遇到了一个问题,导致了这个问题。谢谢你查看这篇文章。不客气,我很高兴你找到了。