Tobias Steele
Tobias Steele

Reputation: 1

Google CSE (Custom Search Engine) - How to determine term user searched for (using jQuery)?

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

Answers (2)

im_dbk
im_dbk

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

dstarh
dstarh

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

Related Questions