在这里,我完全搞不懂如何使用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>然后你就有了谷歌的自定义搜索代码:
<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个?希望你能给我指明正确的方向。
发布于 2015-01-17 07:55:48
在谷歌提供的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是否有效。
然而,我不知道谷歌是否会接受它作为“目标”字段的their docs,比如,“这必须是一个指向与被搜索内容相同的域的地址的网址模式。”另一方面,同一个页面的顶部写着:“你的网站没有搜索引擎吗?你可以用Google自定义搜索引擎设置一个。”
https://stackoverflow.com/questions/26404164
复制相似问题