【问题标题】:Custom Google Search In Webpage [duplicate]网页中的自定义 Google 搜索 [重复]
【发布时间】:2014-01-02 10:20:11
【问题描述】:

我想知道如何进行自己的自定义谷歌搜索。

我可以这样做吗:

<form action="http://www.google.com/search=q?+text input" method="get">
<input type="search">
<input type="submit">
</form>

【问题讨论】:

标签: html forms


【解决方案1】:

试试谷歌为此提供的custom search api。虽然它不是纯 HTML。 以下代码演示了如何使用显式 parsetag 和函数回调在 div 中呈现搜索框以及搜索结果:

<div id="test"></div>

<script>
var myCallback = function() {
  if (document.readyState == 'complete') {
    // Document is ready when CSE element is initialized.
    // Render an element with both search box and search results in div with id 'test'.
    google.search.cse.element.render(
        {
          div: "test",
          tag: 'search'
         });
  } else {
    // Document is not ready yet, when CSE element is initialized.
    google.setOnLoadCallback(function() {
       // Render an element with both search box and search results in div with id 'test'.
        google.search.cse.element.render(
            {
              div: "test",
              tag: 'search'
            });
    }, true);
  }
};

// Insert it before the CSE code snippet so that cse.js can take the script
// parameters, like parsetags, callbacks.
window.__gcse = {
  parsetags: 'explicit',
  callback: myCallback
};

(function() {
  var cx = '123:456'; // Insert your own Custom Search engine ID here
  var gcse = document.createElement('script'); gcse.type = 'text/javascript';
  gcse.async = true;
  gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
      '//www.google.com/cse/cse.js?cx=' + cx;
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>

这是教程link

【讨论】:

    【解决方案2】:

    请参考以下步骤创建谷歌自定义搜索

    1.首先你要注册谷歌账号

    2.转到这个网址 https://www.google.com/cse/create/new

    3.然后指定网站URL(在哪里搜索)

    4.点击创建按钮

    5.在下一页有 3 个可用的按钮,点击“Get Code”按钮。

    6.点击后,生成代码。复制该代码并粘贴到您的网页中。

    【讨论】:

    • 这将为您提供在您的网站内搜索的代码!虽然问题是为网络创建自定义谷歌搜索!
    • 在自定义 google 搜索中,您应该指定至少一个网站 url,并且您可以通过 google 帐户进行搜索设置以进行任何其他搜索
    【解决方案3】:

    Google 有自己的演练, https://www.google.com/cse/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多