Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Jquery History.JS back按钮没有';第一页不太合适_Jquery_Html_Pushstate_History.js - Fatal编程技术网

Jquery History.JS back按钮没有';第一页不太合适

Jquery History.JS back按钮没有';第一页不太合适,jquery,html,pushstate,history.js,Jquery,Html,Pushstate,History.js,我正在使用history.js使用pushState更改页面的URL,同时使用ajax更改内容 我的问题是,我进入的初始页面无法使用返回按钮。内容未存储或我用于获取内容的信息未存储 如果我在初始化时调用pushState,但不知何故,我有两个页面条目。所以当我回击时,我必须再次回击才能进入我的主页。我不知道这是否有意义。在这里似乎找不到任何与我的特殊情况相关的东西 $(function() { var History = window.History; if ( !Histor

我正在使用history.js使用
pushState
更改页面的URL,同时使用ajax更改内容

我的问题是,我进入的初始页面无法使用返回按钮。内容未存储或我用于获取内容的信息未存储

如果我在初始化时调用
pushState
,但不知何故,我有两个页面条目。所以当我回击时,我必须再次回击才能进入我的主页。我不知道这是否有意义。在这里似乎找不到任何与我的特殊情况相关的东西

$(function() {
    var History = window.History; 
    if ( !History.enabled ) {
        return false;
    }
    if($.url().attr('fragment')){
        var url = $.url().attr('fragment').split("-");
    }else{
        var url = $.url().attr('path').split("-");
    }

    photo_ajax(url[3],url[2],url[4]); //perform ajax content update

    //initialize first page but doesn't quite work as it creates two entries
    //History.pushState({pho_id:url[3],per_id:url[2],a_id:url[4]}, "Viewing Photo", $.url().attr('path')); 

    History.Adapter.bind(window,'statechange',function() {
        var State = History.getState();
        photo_ajax(State.data.pho_id,State.data.per_id,State.data.a_id);
    });
});


$(document).ready(function(){  
    $(document).on('click', '[id^="dopho_"]', function(event){
        var id = $(this).attr("id").split('_');
        event.preventDefault();
        History.pushState({pho_id:id[1],per_id:id[2],a_id:id[3]}, "Viewing Photo", $(this).attr('href'));
    });
});

我找到了一些有用的方法。如果我改用
replaceState
,则初始化行可以工作,并且似乎不会出现重复输入。所以我现在就要说这个

$(function() {
        var History = window.History; 
        if ( !History.enabled ) {
            return false;
        }
        if($.url().attr('fragment')){
            var url = $.url().attr('fragment').split("-");
        }else{
            var url = $.url().attr('path').split("-");
        }

        photo_ajax(url[3],url[2],url[4]); //perform ajax content update

        //initialize first page but doesn't quite work as it creates two entries
        History.replaceState({pho_id:url[3],per_id:url[2],a_id:url[4]}, "Viewing Photo", $.url().attr('path')); 

        History.Adapter.bind(window,'statechange',function() {
            var State = History.getState();
            photo_ajax(State.data.pho_id,State.data.per_id,State.data.a_id);
        });
    });


    $(document).ready(function(){  
        $(document).on('click', '[id^="dopho_"]', function(event){
            var id = $(this).attr("id").split('_');
            event.preventDefault();
            History.pushState({pho_id:id[1],per_id:id[2],a_id:id[3]}, "Viewing Photo", $(this).attr('href'));
        });
    });

我找到了一些有用的方法。如果我改用
replaceState
,则初始化行可以工作,并且似乎不会出现重复输入。所以我现在就要说这个

$(function() {
        var History = window.History; 
        if ( !History.enabled ) {
            return false;
        }
        if($.url().attr('fragment')){
            var url = $.url().attr('fragment').split("-");
        }else{
            var url = $.url().attr('path').split("-");
        }

        photo_ajax(url[3],url[2],url[4]); //perform ajax content update

        //initialize first page but doesn't quite work as it creates two entries
        History.replaceState({pho_id:url[3],per_id:url[2],a_id:url[4]}, "Viewing Photo", $.url().attr('path')); 

        History.Adapter.bind(window,'statechange',function() {
            var State = History.getState();
            photo_ajax(State.data.pho_id,State.data.per_id,State.data.a_id);
        });
    });


    $(document).ready(function(){  
        $(document).on('click', '[id^="dopho_"]', function(event){
            var id = $(this).attr("id").split('_');
            event.preventDefault();
            History.pushState({pho_id:id[1],per_id:id[2],a_id:id[3]}, "Viewing Photo", $(this).attr('href'));
        });
    });