How to show next / previous links in links to Google Custom Search

Google Custom Search integration includes only numbered page links, and I cannot find a way to include Next / Previous links, for example, with a normal Google search. CSE used these links with its previous iframe integration method.

+3
source share
3 answers

I went through javascript and found the undocumented properties I was looking for.

<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" />
+3
source

I used this to find the current page:

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

customSearchControl.k[0].g.cursor... (, -)

The next time it stops working, just go to the debug script in IE, add customSearchControl as an hour, open the properties (+), Typefind Object, (Array) in the column and make sure there (+) is there (i.e. contains elements) open[0],, and look Type Objectagain with children. Open it, and as soon as you see the "cursor" in the list, you will get it.

0
source

Source: https://habr.com/ru/post/1755818/


All Articles