javascript - Google 用于 Google 自定义搜索的附加链接搜索框

标签 javascript schema.org google-custom-search google-rich-snippets

我完全不知道如何将 Google 的附加链接搜索框与 Google 的自定义搜索结合使用。

有人知道我是如何开始连接 2 的吗?

Google 为站点链接搜索框提供以下代码:

<script type="application/ld+json">
{
   "@context": "http://schema.org",
   "@type": "WebSite",
   "url": "https://www.example-petstore.com/",
   "potentialAction": {
     "@type": "SearchAction",
     "target": "https://query.example-petstore.com/search?q={search_term_string}",
     "query-input": "required name=search_term_string"
   }
}
</script>

然后您就有了 Google 的自定义搜索代码:

<script>
  (function() {
    var cx = '006674923042857018221:WMX2084923030';
    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>

我究竟如何连接 2?希望你能给我指出正确的方向。

最佳答案

在 Google 提供的 Javascript 代码中有一个 var cx = 'YOUR_LONG_CX_KEY。使用它来填充具有以下 URL 模式的 potentialAction.target:

 "target": "http://www.google.com/cse?cx=YOUR_LONG_CX_KEY&q={search_term_string}",

您可以通过在浏览器中使用您自己的搜索词字符串点击它来确认 URL 是否有效。

但是,我不知道 Google 是否会接受此为 their docs对于“目标”字段说,“这必须是一个 URL 模式,指向与正在搜索的内容位于同一域的地址。”另一方面,同一页面的顶部显示,“您的站点没有搜索引擎?您可以使用 Google 自定义搜索引擎设置一个。”

关于javascript - Google 用于 Google 自定义搜索的附加链接搜索框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26404164/

相关文章:

python - 在 Google 自定义搜索 API 中指定日期范围

c# - Google自定义搜索API指定图像尺寸

javascript - 逗号分隔的正则表达式

javascript - IE9中的IE7和8模式是真的吗?

javascript - 鼠标点击触发鼠标离开

schema.org - Schema.org、Goodrelations-vocabulary.org 和 Productontology.org 之间有什么关系?

javascript - 在 Bootstrap 模式中自定义 Google 搜索,在相同模式中打开结果

javascript - jQuery 将鼠标悬停在排除元素子元素的 li 上

html - "availability"未在 Google Rich Snippet 中显示

google-search - 丰富的摘要仅显示在网站查询中,而不显示在正常搜索中