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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With