Reputation: 1
I have a Google CSE embedded using this:
google.load('search', '1', {language : 'en', style : google.loader.themes.SHINY});
google.setOnLoadCallback(function() {
var options = {};
options[google.search.Search.RESTRICT_EXTENDED_ARGS] = {'sort': 'date'};
var customSearchControl = new google.search.CustomSearchControl('',options);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
I'd like to determine/display the search term the user searches for, but I can't seem to get the search term out of the Google CSE input after the user clicks "search".
How can I do this?
Upvotes: 0
Views: 1015
Reputation: 21
This should get it:
var customSearchControl = new google.search.CustomSearchControl('your key');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
// add this
customSearchControl.setSearchStartingCallback(this,
function(sc, searcher, query) {
alert(query);
// or do whatever you want with it here.
}
);
Upvotes: 2
Reputation: 5076
Shouldnt the search terms be available in the header that is returned, I'm wondering if you cant get access to the actual ajax request and then use jquery to access the header object. I know when doing a regular search on google the keywords are passed along in the header.
Upvotes: 0