【问题标题】:How to show next/previous links in Google Custom Search Engine paging links如何在 Google 自定义搜索引擎分页链接中显示下一个/上一个链接
【发布时间】:2010-07-21 18:24:53
【问题描述】:

Google 自定义搜索集成仅包含编号的页面链接,我找不到像普通 Google 搜索那样包含下一个/上一个链接的方法。 CSE 过去常常将这些链接包含在他们以前的 iframe 集成方法中。

【问题讨论】:

    标签: google-custom-search


    【解决方案1】:

    我浏览了 javascript 并找到了我正在寻找的未记录的属性。

    <div id="cse" style="width: 100%;">Loading</div>
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript">
    
    google.load('search', '1', {language : 'en'});
    google.setOnLoadCallback(function() {
        var customSearchControl = new google.search.CustomSearchControl('GOOGLEIDGOESHERE');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        customSearchControl.setSearchCompleteCallback(null, 
            function() { searchCompleteCallback(customSearchControl) });
    
        customSearchControl.draw('cse');   
    }, true);
    
    
    function searchCompleteCallback(customSearchControl) {
    
        var currentPageIndex = customSearchControl.e[0].g.cursor.currentPageIndex;
    
        if (currentPageIndex < customSearchControl.e[0].g.cursor.pages.length - 1) {
            $('#cse .gsc-cursor').append('<div class="gsc-cursor-page">Next</div>').click(function() {
                customSearchControl.e[0].g.gotoPage(currentPageIndex + 1);
            });
        }
    
        if (currentPageIndex > 0) {
            $($('#cse .gsc-cursor').prepend('<div class="gsc-cursor-page">Previous</div>').children()[0]).click(function() {
                customSearchControl.e[0].g.gotoPage(currentPageIndex - 1);
            });
        }
    
        window.scrollTo(0, 0);
    
    }
    </script>
    
    <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
    

    【讨论】:

    • 我一直在使用这个解决方案,直到它意外损坏。使用上面的确切代码不再有效。我收到此错误:customSearchControl.e[0].g 未定义
    • 看起来他们更改了未记录的属性? ://
    • 是的,将 e[0].g 更改为 e[0].h,现在一切都很好。
    • 是否有人遇到过 IE 和自定义搜索中的分页问题?出于某种原因,我必须单击两次链接才能使 IE 正常工作。
    【解决方案2】:

    我一直在用它来查找当前页面:

    ctrl.setSearchCompleteCallback(null, function(gControl, gResults)
    {
        currentpage = 1+gResults.cursor.currentPageIndex;
        // or, here is an alternate way
        currentpage = $('.gsc-cursor-current-page').text();
    });
    

    【讨论】:

      【解决方案3】:

      现在是customSearchControl.k[0].g.cursor ...(似乎是本周末)

      下次它停止工作时,只需在 IE 中进行脚本调试,将 customSearchControl 添加为监视,打开属性 (+),在 Type 列下查找 Object, (Array) 并确保有(+) 也在那里(即包含元素)open[0],并再次查找 Type Object,以及子元素。打开它,一旦你在列表中看到“光标”,你就知道了。

      【讨论】:

        猜你喜欢
        • 2013-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-23
        • 2014-11-26
        • 2010-11-23
        • 2011-06-07
        • 1970-01-01
        相关资源
        最近更新 更多