在Google申请的站内搜索代码因为有Form的原因,而Csdn博客框架中已经有了一个Form,因此形成了Form套嵌,Google的form就失去了效果。
这里通过可以通过去掉google的form,并在提交按钮上的onclick事件和javascript的配合来解决这个问题,如下:
onclick="document.getElementById('Form1').target='google_window';document.getElementById('Form1').action='http://www.google.cn/search'; document.getElementById('Form1').method ='get';"我申请的Google代码:
<!-- SiteSearch Google -->
<form method="get" action="http://www.google.cn/search" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
<br/>
<input type="hidden" name="domains" value="csdn.net;blogjava.net"></input>
<label for="sbi" style="display: none">输入您的搜索字词</label>
<input type="text" name="q" size="24" maxlength="255" value="" id="sbi"></input>
</td></tr>
<tr>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" checked id="ss0"></input>
<label for="ss0" title="搜索网络"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="csdn.net" id="ss1"></input>
<label for="ss1" title="搜索 csdn.net"><font size="-1" color="#000000">csdn.net</font></label></td>
</tr>
<tr>
<td>
<input type="radio" name="sitesearch" value="blogjava.net" id="ss2"></input>
<label for="ss2" title="搜索 blogjava.net"><font size="-1" color="#000000">blogjava.net</font></label></td>
<td></td>
</tr>
</table>
<label for="sbb" style="display: none">提交搜索表单</label>
<input type="submit" name="sa" value="搜索" id="sbb"></input>
<input type="hidden" name="client" value="pub-5618746900064278"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="prog" value="aff"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1"></input>
<input type="hidden" name="hl" value="zh-CN"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->经过修改后的代码:
<!-- SiteSearch Google -->
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
<br/>
<input type="hidden" name="domains" value="csdn.net;blogjava.net"></input>
<label for="sbi" style="display: none">输入您的搜索字词</label>
<input type="text" name="q" size="24" maxlength="255" value="" id="sbi"></input>
</td></tr>
<tr>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" checked id="ss0"></input>
<label for="ss0" title="搜索网络"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="csdn.net" id="ss1"></input>
<label for="ss1" title="搜索 csdn.net"><font size="-1" color="#000000">csdn</font></label></td>
</tr>
<tr>
<td>
<input type="radio" name="sitesearch" value="blogjava.net" id="ss2"></input>
<label for="ss2" title="搜索 blogjava.net"><font size="-1" color="#000000">blogjava</font></label></td>
<td></td>
</tr>
</table>
<label for="sbb" style="display: none">提交搜索表单</label>
<input type="submit" name="sa" value="搜索" id="sbb" onclick="document.getElementById('Form1').target='google_window';document.getElementById('Form1').action='http://www.google.cn/search'; document.getElementById('Form1').method ='get';"></input>
<input type="hidden" name="client" value="pub-5618746900064278"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="prog" value="aff"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="cof" 
value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1"></input>
<input type="hidden" name="hl" value="zh-CN"></input>
</td></tr></table>
<!-- SiteSearch Google -->

展示的效果可以看我博客左边的Google搜索。
本文介绍了一种解决Google站内搜索代码与CSDN博客框架冲突的方法,通过去除原Form并利用JavaScript重新定义搜索行为,确保了搜索功能的正常运作。
588

被折叠的 条评论
为什么被折叠?



