0

请考虑以下问题(问题是,我们页面上的 Google 搜索结果未在我们的 Google Analytics 帐户中注册):

HTML表格:

    <div style="float:right; margin-right:12px;">
    <form id="cse-search-box" name="srchfrm" action="http://google.com/cse" target="_blank" onsubmit="validatesearch()">
        <input value="999999999999999999999:srraaaaaaaa" name="cx" type="hidden"/>
        <input id="q" name="q" type="text" onKeyPress="return submitenter(this,event)" placeholder="Search"/>
        <a href="javascript:;" onmouseover="MM_swapImage('go','','/btn_go_on.gif',1)" onmouseout="MM_swapImgRestore()" />
        <input type="image" src="/btn_go.gif" alt="Go" width="20" height="21" border="0" align="top" id="go"/>
        <input value="UTF-8" name="ie" type="hidden"/>    
    </form> 
</div>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('search', '1');
  google.setOnLoadCallback(function() {
    google.search.CustomSearchControl.attachAutoCompletion(
      '999999999999999999999:srraaaaaaaa',
      document.getElementById('q'),
      'cse-search-box');
  });
</script>

执行搜索的 URL:

http://www.google.com/cse?cx=999999999999999999999:srraaaaaaaa&q=test+search&x=12&y=11&ie=UTF-8&oq=&gs_l=#gsc.tab=0&gsc.q=test%20search&gsc.page=1

正在使用的查询参数:

q
query (I read in another post to try this)

感谢您提前提供的所有帮助!

4

1 回答 1

1

通过改变:

action="http://google.com/cse"

之内,

<form id="cse-search-box" name="srchfrm" action="http://google.com/cse" target="_blank" onsubmit="validatesearch()">

重定向到网站内的页面,这解决了这个问题。

工作代码:

<div style="float:right; margin-right:12px;">
    <form id="searchbox_99999999999999999999:srraaaaaaaa" name="srchfrm" action="/search" target="_self" onsubmit="validatesearch()">
        <input value="99999999999999999999:srraaaaaaaa" name="cx" type="hidden"/>
        <input id="q" name="q" autocomplete="off" type="text" onKeyPress="return submitenter(this,event)" placeholder="Search"/>
        <input name="ie" value="UTF-8" type="hidden"/>
        <a href="javascript:;" onmouseover="MM_swapImage('go','','/btn_go_on.png',1)" onmouseout="MM_swapImgRestore()" />
        <input type="image" src="/btn_go.png" alt="Go" width="20" height="21" border="0" align="top" id="go"/> 
    </form> 
</div>

根据 Google 文档,搜索页面本身具有以下代码:

头:

<script>
  (function() {
    var cx = '99999999999999999999:srraaaaaaaa';
    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:searchresults-only></gcse:searchresults-only>
于 2012-10-26T16:13:15.907 回答