【发布时间】:2014-03-19 16:50:42
【问题描述】:
我正在尝试使用 Google 自定义搜索 (GCS) 在同一页面上设置多个搜索字段,如下所示:
<script>
(function() {
var cx = 'user_id:field_id1';
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>
<gcse:search></gcse:search>
<script>
(function() {
var cx = 'user_id:field_id2';
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>
<gcse:search></gcse:search>
不幸的是,它不起作用。对每个字段使用相同的cx 进行搜索。当它对该地址执行 ajax 请求时:https://www.googleapis.com/customsearch/v1element... 有这个值:&cx=user_id:field_id1,并且两个字段的值相同。
解决办法是什么?
我已经看到了这个问题:Multiple Google CSE (Custom Search Engine) Boxes on Same Page,但它似乎在另一个版本上。
【问题讨论】:
标签: javascript google-custom-search