【发布时间】:2014-07-26 01:58:41
【问题描述】:
我有一个主页所在的搜索系统:
http://example.com/
结果页面(完全不同)位于:
http://example.com/?q=foo
我正在尝试设置引导程序浏览,以便它从主页开始,然后将用户带到结果页面。所以我有如下步骤:
{
path: '/',
element: "#extra-sidebar-fields",
backdrop: true,
title: "Sophisticated Search",
content: "In the Advanced Search area, you can make sophisticated searches against many fields. " +
"Press \"Next\" and we'll make a query for you.",
},
{
path: '/?q=roe+v+wade',
element: 'article:first',
title: 'Detailed Results',
content: 'Here you can see the results for the query "Roe v Wade" sorted by relevance.'
}
我遇到的问题是游览不明白需要执行GET请求来加载第二步,所以我想我需要使用redirect键什么的。
如果我在不同的路径上有搜索结果,这将非常有效,但由于主页和结果都在 /,看来我被卡住了。
编辑...
公开工作,自发布此消息以来,我已经尝试了一些事情。首先,我认为我可以通过使用 onNext 参数来完成重定向,所以我将第一步更改为:
{
path: '/',
element: "#extra-sidebar-fields",
backdrop: true,
title: "Sophisticated Search",
content: "In the Advanced Search area, you can make sophisticated searches against many fields. " +
"Press \"Next\" and we'll make a query for you.",
onNext: function(){
window.location = '/?q=row+v+wade'
},
},
{
path: '/?q=roe+v+wade',
element: 'article:first',
title: 'Detailed Results',
content: 'Here you can see the results for the query "Roe v Wade" sorted by relevance.'
}
这不起作用,因为虽然重定向正确发生(很好!),但在此之前用户会看到下一步弹出,并且根据他们的连接速度,它可能会在重定向前一段时间可见完成的。所以除非我能阻止下一步弹出,否则这个策略是没有用的。
我尝试了另一种策略,重新定义了 _isRedirect 方法:
tour._isRedirect = function(path, currentPath){
return (path != null) && //Return false if path is undefined.
path !== "" && (
({}.toString.call(path) === "[object RegExp]" && !path.test(currentPath)) ||
({}.toString.call(path) === "[object String]" &&
path.replace(/\/?$/, "") !== currentPath.replace(/\/?$/, "")
)
);
}
通常它有一行去掉 GET 参数 (path.replace(/\?.*$/, "")),所以我修改它不这样做。这种改变也有点奏效。重定向正确发生,但没有显示下一步,但不幸的是,此更改使其具有重定向循环......或类似的东西。它只是一遍又一遍地重定向。
不知道接下来我会做什么。可以借助更精通 JS 的人的帮助。
【问题讨论】:
-
我有一种感觉,BS Tour 不适合这样使用。游览通常会跳过单个页面上的元素,让它执行整个页面重新加载似乎很奇怪。
-
不,它通过路径属性支持多页,但它似乎不支持 GET 参数。
标签: javascript twitter-bootstrap get bootstrap-tour