2010-07-21 71 views

回答

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" /> 
+2

我用這個解決方案,直到它會突然出現。使用上面的確切代碼不再有效。我得到這個錯誤:customSearchControl.e [0] .g未定義 – Ian 2010-09-21 22:30:14

+0

看起來他們改變了他們的未記錄的屬性? :/ – Ian 2010-09-21 22:30:59

+0

是的,將e [0] .g更改爲e [0] .h,一切正常...現在。 – Ian 2010-09-21 22:36:10

0

現在它的customSearchControl.k[0].g.cursor ...(本週末,似乎)

下一次它停止工作只是去調試腳本在IE中添加customSearchControl如鐘錶,打開屬性( +),在Type列下查找Object(數組),並確保也有(+)(即包含元素),open[0],並再次查找Type Object子元素。打開它,一旦你在列表中看到「光標」,你就知道了。

1

我一直在使用這一方法查找當前頁面:

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