【问题标题】:Google free site search, post query谷歌免费网站搜索,帖子查询
【发布时间】:2011-09-22 15:18:57
【问题描述】:

我有一个谷歌网站搜索

http://www.google.com/cse/manage/create

这给了我以下工作代码:

<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    google.load('search', '1', { language: 'en' });
    google.setOnLoadCallback(function () {
        var customSearchControl = new google.search.CustomSearchControl('013080392637799242034:ichqh_hal4w');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        customSearchControl.draw('cse');
    }, true);
</script>

在我的某些页面上,我有一个搜索框。我可以在该搜索框中输入文本,发布到该站点搜索脚本并加载吗?

例如:

  • 用户在 Home.html 上
  • 他们在搜索框中输入文本
  • 将它们重定向到 Search.html
  • Search.html 获取他们输入的文本并使用它进行搜索,而无需在空框中重新键入它

目前我有:

// Temporary measure
SearchBox.click(function (event) {
    SearchBox.attr('disabled', 'disabled');
    SearchBox.css("background", "#efefef");
    window.location.replace(Domainroot + "/search");
});

这不太理想,但工作正常。当用户点击搜索框时,它会将他们重定向到搜索页面,以保存他们重复输入查询。

感谢您的帮助!

【问题讨论】:

    标签: javascript jquery search google-sites


    【解决方案1】:

    看看http://code.google.com/apis/customsearch/docs/js/cselement-reference.html#_methods-el

    看起来您创建的控件带有方法。看来您正在寻找 .execute(query) 方法。

    【讨论】:

      【解决方案2】:

      一种方法是将 iFrame 代码直接放在您的主页上,您可以对其进行自定义。你会找到各种方法来做到这一点。但是如果你想要一个更个性化的东西,比如有一个搜索框,然后在你的页面中显示结果,那么我建议你做一个后端过程来查询谷歌,然后发回结果。查看 Nokogiri 示例了解我的意思。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 2014-05-25
        • 2012-07-16
        • 1970-01-01
        相关资源
        最近更新 更多