Starting Bootstrap tour with a button after ending tour once

旧时模样 提交于 2019-12-23 02:36:43

问题


I have a simple web page with content and bootstrap tour to guide through my web page.

I would like to trigger the tour with a button with following html code:

<button id="initiate_tour" type="button" class="btn btn-danger">Initiate Tour</button>

The JS for initiating the tour is as follows:

// Instance the tour
var tour = new Tour({
  backdrop: false, 
  storage: false        
});

tour.addSteps([
    {
        element: "#1",
        title: "title1",
        content: "content1"
    },
    {
        element: "#2",
        title: "title2",
        content: "content2"
    },
    {
        element: "#3",
        title: "title3",
        content: "content3"
    },
    {
        element: "#4",
        title: "title4",
        content: "content4"
    }

  ]);

$("#initiate_tour").click(function(){
    // Start the tour
    tour.start();

});

I am able to start the tour when I click the button Initiate Tour. When I click End Tour button the tour closes. But when I click the Initiate Tour button again the tour doesn't start.

I have refereed following posts but nothing worked:post1 and post2.

Please help me out solving this as am new to using javascript and bootstrap tour


回答1:


You can restart the tour using the restart() function.

http://jsfiddle.net/tejashsoni111/6hh8z5qc/1/

$("#initiate_tour").click(function(){
    // Start the tour
    if(!tour.start()){
        tour.restart();
    }
});



回答2:


Now the tour is working as expected. I have enabled debug as true in bootstrap tour settings to see log in the console of browser. I got error which says "Tour ended, init prevented".

Made following change in code:

$("#initiate_tour").click(function(){
    tour.init();
    tour.restart();
});

Got the solution from following link: problem solution



来源:https://stackoverflow.com/questions/40262379/starting-bootstrap-tour-with-a-button-after-ending-tour-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!