Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我做错了什么?使用NationBuilder实现自定义Google搜索_Javascript_Liquid_Implementation_Google Custom Search_Language Implementation - Fatal编程技术网

Javascript 我做错了什么?使用NationBuilder实现自定义Google搜索

Javascript 我做错了什么?使用NationBuilder实现自定义Google搜索,javascript,liquid,implementation,google-custom-search,language-implementation,Javascript,Liquid,Implementation,Google Custom Search,Language Implementation,我遵循了关于如何使用NationBuilder()实现自定义Google搜索的所有说明 网站上会出现搜索栏,但不会出现搜索结果。(此处的网站示例:) 我在这段代码中要自定义什么来实现结果?我添加了我的自定义搜索id,但我觉得我还必须更改其他内容: <form method="get" action="/search"> <div class="row"> <div class="col

我遵循了关于如何使用NationBuilder()实现自定义Google搜索的所有说明

网站上会出现搜索栏,但不会出现搜索结果。(此处的网站示例:)

我在这段代码中要自定义什么来实现结果?我添加了我的自定义搜索id,但我觉得我还必须更改其他内容:

<form method="get" action="/search">
  <div class="row">
    <div class="col-lg-6">
      <div class="input-group">
        <input name="q" type="search" placeholder="Enter keywords..." class="form-control" />
        <span class="input-group-btn">
          <input class="btn btn-primary" type="submit" value="SEARCH" />
        </span>
      </div>
    </div>
  </div>
</form>
<script type="text/javascript">
  (function() {
    function getUrlParameter(name) {
      name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
      var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
      var results = regex.exec(location.search);
      return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
    };
    document.getElementsByName("q").forEach(function(el){el.value = getUrlParameter("q")});
    var cx = '{% if custom_search_id and custom_search_id != "" %}{{ custom_search_id }}{% else %}008016235122236849965:29prjnksala{% endif %}';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<div class="row">
  <div class="gcse-searchresults-only" data-enableAutoComplete="true" data-safeSearch="active" data-as_sitesearch="{{ site.full_url | split:'//' | last | split:'/' | first }}" data-image_as_sitesearch="{{ site.full_url | split:'//' | last | split:'/' | first }}" data-enableImageSearch="false" data-disableWebSearch="false"></div>
</div>

(功能(){
函数getUrlParameter(名称){
name=name.replace(/[\[]/,'\\[')。replace(/[\]]/,'\\]');
var regex=new RegExp('[\\?&]'+name+'=([^&\\]*));
var results=regex.exec(location.search);
返回结果===null?“”:decodeURIComponent(结果[1]。替换(/\+/g');
};
document.getElementsByName(“q”).forEach(函数(el){el.value=getUrlParameter(“q”)});
var cx='{%if自定义搜索id和自定义搜索id!='%}{{{custom搜索id}}{%else%}008016235122236849965:29prjnksala{%endif%}';
var gcse=document.createElement('script');
gcse.type='text/javascript';
gcse.async=true;
gcse.src=(document.location.protocol=='https:'?'https:':'http:')+'/cse.google.com/cse.js?cx='+cx;
var s=document.getElementsByTagName('script')[0];
s、 parentNode.insertBefore(gcse,s);
})();

看起来cx ID以某种方式连接起来了。浏览器发出请求,返回404错误


有两个不同的cx ID(02a15aadc5f939bbe和008016235122236849965:29prjnksala)混合在一起

谢谢,安迪!我猜这是一行代码:var cx='{%if custom_search_id和custom_search_id!=''%}{{{custom_search_id}}{%else%}008016235122236849965:29prjnksala{%endif%};添加自定义搜索ID需要代码的正确部分是什么?