Google搜索栏脚本无效

时间:2017-03-30 13:51:42

标签: javascript html google-search-api

您好我正在尝试使用Google搜索栏脚本在我的网站上运行。

当你第一次在页面上看起来像是角落里的放大镜(就像这样) magnify

然后,一旦你点击放大玻璃,它就进入了这个状态 searchbar

由于某种原因,搜索栏仅在网站的主页上工作(没有较低级别的页面),并且它不完全搜索我们的网站。

我的代码如下:

搜索脚本

   <div class="hide" >
    <script>
    (function() {
        var cx = '000937597557157891839:ruyewipqtri';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
       var s = document.getElementsByTagName('script')[0];
       s.parentNode.insertBefore(gcse, s);
       })();
       </script>
        <gcse:searchbox-only gname="search-box"   resultsUrl="//test.iowalum.com/search-results/"></gcse:searchbox-only>
        </div>

我一直试图让resultsURL发生变化,因为我们不再在我们的测试服务器上它应该只是iowalum.com但是每当我更改该URL时它都会破坏网站。

我的搜索结果脚本是:

    <script>
    (function() {
     var cx = '000937597557157891839:ruyewipqtri';
     var gcse = document.createElement('script');
     gcse.type = 'text/javascript';
     gcse.async = true;
     gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
     var s = document.getElementsByTagName('script')[0];
     s.parentNode.insertBefore(gcse, s);
     })();
     </script>
     <style>
     .gsc-control-wrapper-cse {
      padding:0;    
      }
     .gsc-results-wrapper-nooverlay {
      padding: 0;
      }
      .gsc-wrapper {
       padding: 0;
      }
      </style>
      <gcse:searchresults-only></gcse:searchresults-only>

最后,每个网页上的实际搜索部分或包括:

     <li class="search-module" search min-z-index-toggle="0">

           <!-- <div class="input-container">
            <input search-input class="search-input" aria-label="find   something...">
             <div class="placeholder-SHIV">find something...</div>
           </div> -->

            <div class="input-container">
             <cfinclude template = "//_includes/search.cfm">
             <div class="placeholder-SHIV">find something...</div>
            </div>

            <a search-button class="button icon svg-container">
            <svg class="svg-icon" viewBox="0 0 50 50"><use   xlink:href="#svg-search"></svg>
            </a>
            </li>




Here I have the same issue as with the search URL whenever I attempt
to change the path the site breaks. I think this might be why it's 
only working on the home page though since it is not the full path
 and others are sub pages?

任何帮助都会很棒!

谢谢!

0 个答案:

没有答案