0

我的网站上当前正在运行一个游览,但它似乎并没有真正跟踪用户是否单击了结束游览。这意味着如果他们单击一次,它会结束游览,但是当他们重新访问该页面时,游览将自动重新开始,就好像这是他们第一次登陆该页面一样。

var tour = new Tour({
    backdrop:true,
    onEnd:function(t){
        var last = t._options.steps.length;
        if(t._current==last-1){
            $.post( "home/tourCompleted", function( data ) {});
            //$('#tourTracking').attr("step",0);
            //$("#tourTracking").addClass("hidden");
        }else{
            if(t._current==0){
                $.post( "home/setCurrentStepTour/0", function( data ) {});
                //$('#tourTracking').attr("step",0);
            }else{
                $.post( "home/setCurrentStepTour/"+t._current, function( data ) {});
                //$('#tourTracking').attr("step",t._current);
            }
        }

        if($.browser.device){
            $("#dropdownToolbar").removeClass("open4tour open");
        }

        $("html,body").css('overflow', 'auto');
        document.body.removeEventListener('touchstart',null);

    },
    onShown: function(tour) {
        var stepElement = getTourElement(tour);
        $(stepElement).after($('.tour-step-background'));
        $(stepElement).after($('.tour-backdrop'));
    }
});

function getTourElement(tour){
    return tour._options.steps[tour._current].element
}

var bookcount = <?php echo count($lstscbook)?>;

if (bookcount == 0){
    $('.tour-tour-0').addClass('noBookTour');
    tour.addSteps([
        {...}
    ]);
}else{ ... }

<?if(isset($redir4tour) && $redir4tour==TRUE){?>

    var redir4tour=true;
<?}else{?>
    var redir4tour=false;
<?}?>

if(redir4tour)window.history.pushState({},"", "<?=base_url()?>");

if(($('#tourTracking').attr("step")==0 && !(<?php echo (isset($tour['completed']) ? $tour['completed'] : "false" )?>)) || redir4tour){
    document.body.addEventListener('touchstart', function(e){ return true; });
    $("html,body").css('overflow', 'hidden');
    window.scrollTo(0, 0);
    tour.init();
    tour.restart(); //using restart -> https://github.com/sorich87/bootstrap-tour/issues/140
}

$("a#tourTracking").click(function(e){
    document.body.addEventListener('touchstart', function(e){ return true; });
    $("html,body").css('overflow', 'hidden');
    window.scrollTo(0, 0);
    var step = $('#tourTracking').attr("step");
    if($.browser.device && (step==2 || step==14 || step==19 || step==20 || step==21)){//steps in toolbar responsive. have to open toolbar before set step!
        $("#dropdownToolbar").addClass("open4tour");
        $("#responsiveToolbar").click();
    }

    window.localStorage.clear();
    tour.setCurrentStep(step);
    tour.init();
    tour.restart(); //using restart -> https://github.com/sorich87/bootstrap-tour/issues/140
});
4

3 回答 3

1

我相信这默认使用 window.localStorage 进行持久性。你window.localStorage.clear();在最后清除这个吗?

于 2015-09-09T16:29:20.773 回答
0

我必须在初始化 "var tour = new Tour({"

name: 'tourNew' + Date.now().toString(),

试试看,看看它是否也适合你。

于 2018-09-21T20:46:02.477 回答
0

您可以设置选项:storage: false禁用此行为

于 2018-09-21T01:59:44.977 回答