【问题标题】:Google CSE (Custom Search Engine) - How to determine term user searched for (using jQuery)?Google CSE(自定义搜索引擎) - 如何确定用户搜索的术语(使用 jQuery)?
【发布时间】:2010-12-14 14:08:42
【问题描述】:

我有一个使用这个嵌入的 Google 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 输入中获取搜索词。

我该怎么做?

【问题讨论】:

    标签: google-search google-custom-search


    【解决方案1】:

    这应该得到它:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我很n00b,所以我的回答会受到限制,但是:我进行了搜索并得到了结果。我使用 Firebug 来查看页面源代码。我没有在任何地方找到我的搜索词。这与您的评论有关吗?
      • 它将在从 ajax 请求返回的标头数据中
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多