簡體   English   中英

如何使Bootstrap Tour應用GET參數

[英]How to make Bootstrap Tour apply GET parameters

我有一個搜索系統,其主頁位於:

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方式中使用更精明的人的幫助。

嘗試將行號431更改為此

   return (path != null) && path !== "" && (({}.toString.call(path) === "[object RegExp]" && !path.test(currentPath)) || ({}.toString.call(path) === "[object String]" && path !== currentPath));

默認情況下,該行會去除“?” 對於currentPath和path。 因此,當path = "/?q=roe+v+wade"currentPath = "/"q=roe+v+wade被剝離,因此path和currentPath相等,因此不會啟動重定向。

編輯:發現我最初的答案有問題。 將第292行更新為

    current_path = [document.location.pathname, document.location.search, document.location.hash].join("");

current_path變量(輸入到isRedirect函數中)最初僅獲取路徑名和哈希值。 document.location.search的添加還告訴它也可以獲取get vars-我必須說,我不是100%肯定瀏覽器的兼容性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM