Bootstrap Tour - 每个用户具有不同价值的URL

时间:2015-07-08 14:04:46

标签: javascript twitter-bootstrap bootstrap-tour

我查看了其他问题/答案,但我找不到解决我问题的问题。我查看了原始文档here,但解决方案对我没有意义。

以下代码中的路径因用户而异。

onNext: function(){
        document.location.href = 'http://localhost:8080/web/client/biography';
      },

接下来,用户将根据用户名指向不同的路径。

如何确保每个用户的网址都正确?

http://localhost:8080/web/client/biography
http://localhost:8080/web/client1/biography
http://localhost:8080/web/client2/biography

我的代码:

 <script>
// Instance the tour
var tour = new Tour({
	name: "tour",
  steps: [],
  container: "body",
  keyboard: true,
  storage: window.localStorage,
  debug: false,
  backdrop: true,
  backdropContainer: 'body',
  backdropPadding: 0,
  steps: [
  {
    element: ".logo",
    title: "Setup Wizard",
    content: "Synergistically visualize maintainable metrics vis-a-vis.",
  },
  {
    //element: "#groups",
    //backdrop: false,
  //  title: "Setup Wizard",
   // content: "Synergistically visualize maintainable metrics vis-a-vis."
   
  },
  {
    element: ".group-content",
    //backdrop: false,
    onNext: function(){
        document.location.href = 'http://localhost:8080/web/client/biography';
      },
    title: "Setup Wizard",
    content: "To get started we'd like you to setup your group subscriptions, and later tell us a bit more about yourself. Please tick your interested groups and click on Save"
  },
  {
    element: ".user-profile-portlet",
    onEnd: function(){
        document.location.href = 'http://localhost:8080/user/client/home';
      },
    title: "Setup Wizard",
    content: "Go ahead and click on 'edit' and tell us a bit more about yourself."
    
  }
 
]});

// Initialize the tour
tour.init();

// Start the tour
tour.start();
    </script>
 

1 个答案:

答案 0 :(得分:0)

@Adriano Repetti的答案很好,实际上应该被视为最佳实践。但是,由于很多原因,我无法在服务器端更改很多东西,使用liferay门户网站就是其中之一!

如果其他人也有兴趣知道这里的答案是我的解决方案:

在您的脚本中添加:

onNext: function(){
        var n=window.location.href;
        //alert(n);
        n=n.replace('/user/','/web/').replace('/groups','/biography');
        document.location.href = n;
      },

这告诉tour找到当前的url并将其分配给n。然后将/ user / with / web /替换为依此类推。然后将新值赋给n并告诉onNext函数点击它!

我希望这会有所帮助:)