Google Site Search - Cookie?

时间:2013-11-11 17:27:50

标签: google-search google-search-api

我在网站上使用Google Site Search。 在我们开始使用cookie之前,网站上有一个cookie提示符,要求用户接受cookie。这工作正常。但是,在我们实施Google搜索之后,事实证明Google还有几个Cookie。

我的问题是;在用户接受这些cookie(或其他参数)之前,我们如何让Google不使用这些cookie。

以下基本示例将使Google创建2个Cookie:

<script>
(function() {
  var cx = '012:345'; // 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>

<gcse:search></gcse:search>

任何想法如何解决/解决这个问题?

1 个答案:

答案 0 :(得分:1)

上面的代码负责加载脚本google.com/cse.js。您可以等到用户接受cookie策略,而不是立即执行该功能:

<script>
var loadScript = function() {
  var cx = '012:345'; // 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);
};

// Here ask user for cookies etc.

// Then load script.
loadScript();
</script>

<gcse:search></gcse:search>
相关问题