Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to register a search result callback when using Google CSE v2?

In version one (v1) of Google's Custom Search Engine code, there was a method called .setSearchCompleteCallback which would allow you to call some Javascript when the search results had returned. The documentation for that code can be found here.

The search engine object has been moved from google.search.CustomSearchControl in v1 to google.search.cse.element in v2.

The current version (v2) doesn't seem to have the .setSearchCompleteCallback method, and I can't see a way to register a callback for when the search results are finished. I have experimented to varying degrees of success with Jquery's ajaxStart and ajaxEnd methods, but I wondered if there was an "official" way to do this built into the Google CSE code.

like image 829
Andy F Avatar asked Oct 08 '12 14:10

Andy F


1 Answers

Not elegant, but the only thing I could find.

I know people are going to comment about using an interval that never ends, but until a better solution is found this is what we have.

setInterval(function () {
    var resultInfo = $('.gsc-result:first');
    if (resultInfo.length && !resultInfo.data('isOld')) {
        resultInfo.data('isOld', true);

        console.log('new results');
    }
}, 500);
like image 120
Eric Avatar answered Nov 09 '22 22:11

Eric