CSDN博客加Google搜索的方法

在Google申请的站内搜索代码因为有Form的原因,而Csdn博客框架中已经有了一个Form,因此形成了Form套嵌,Google的form就失去了效果。

这里通过可以通过去掉google的form,并在提交按钮上的onclick事件和javascript的配合来解决这个问题,如下:

οnclick="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" >
< 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" >
< 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搜索。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值