2010-12-14 71 views
0

我用这个谷歌的CSE嵌入:谷歌CSE(自定义搜索引擎) - 如何确定术语用户搜索(使用jQuery)?

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

我想确定/显示搜索词的用户搜索,但我似乎无法得到搜索词了CSE谷歌的用户点击“搜索”后输入。

我该怎么做?

回答

0

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

+0

我相当的n00b,所以我的回答将是有限的,但是: 我做了搜索,得到的结果。我使用Firebug来查看页面源代码。我没有在任何地方找到我的搜索字词。这与您的评论有关吗? – 2010-12-15 01:21:40

+0

它会在从ajax请求返回的标题数据中 – dstarh 2010-12-15 20:54:33

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. 
     } 
);