0

我有一个使用这个嵌入的谷歌 CSE:

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');

我想确定/显示用户搜索的搜索词,但在用户单击“搜索”后,我似乎无法从 Google CSE 输入中获取搜索词。

我怎样才能做到这一点?

4

2 回答 2

2

这应该得到它:

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.
        }
);
于 2011-05-13T16:59:21.937 回答
0

搜索词是否应该在返回的标头中可用,我想知道您是否无法访问实际的 ajax 请求,然后使用 jquery 访问标头对象。我知道在谷歌上进行常规搜索时,关键字会在标题中传递。

于 2010-12-14T15:12:48.820 回答