3

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

4

3 回答 3

3

我逐步浏览了 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" />
于 2010-07-21T18:28:44.523 回答
1

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

ctrl.setSearchCompleteCallback(null, function(gControl, gResults)
{
    currentpage = 1+gResults.cursor.currentPageIndex;
    // or, here is an alternate way
    currentpage = $('.gsc-cursor-current-page').text();
});
于 2011-11-09T21:17:24.650 回答
0

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

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

于 2011-05-09T13:58:31.940 回答