搜Google狗

本文介绍了一个使用JavaScript实现的双搜索引擎对比工具,该工具允许用户同时在Google和搜狗上搜索同一关键词,并直观地比较搜索结果。文章包含了实现这一功能的源代码,包括URL编码和解码函数,以及用于切换显示不同搜索引擎结果的按钮。
    前几天突然想起来 http://baigoogledu.com这个网站,那时候还是我在北京的时候那个市场的苏鑫磊告诉我的这个无敌的网站,就是将两个搜索集成到一起好让搜索的内容直观的做对比,闲来无事也来实现一个。
看了看这个网站是使用的ASP,我就拿JAVASCRIPT来实现一下。麻烦的是Google还需要UrlEncode编码,否则显示中文还有问题。今天解决了,发上来代码给大家共享一下。有机会就架到空间上。

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
< title > 搜Google狗 </ title >
< script  language ="vbscript" >  
//使用vbscript来进行解码或加密
Function str2asc(strstr) 
str2asc 
= hex(asc(strstr)) 
End Function 
Function asc2str(ascasc) 
asc2str 
= chr(ascasc) 
End Function 
</ script >  

< script  language ="javascript" >  
/**//*这里开始时UrlEncode和UrlDecode函数*/ 
function UrlDecode(str)
//解码
   var ret=""
   
for(var i=0;i<str.length;i++)
   
var chr = str.charAt(i); 
     
if(chr == "+")
       ret
+=" "
     }
else if(chr=="%")
     
var asc = str.substring(i+1,i+3); 
     
if(parseInt("0x"+asc)>0x7f)
       ret
+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
       i
+=5
     }
else
       ret
+=asc2str(parseInt("0x"+asc)); 
       i
+=2
     }
 
     }
else
       ret
+= chr; 
     }
 
   }
 
   
return ret; 
}
 


function UrlEncode(str)
//加密
   var ret=""
   
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
   for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
     var c=str2asc(chr); 
     if(parseInt("0x"+c) > 0x7f){ 
       ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
     }else{ 
       if(chr==" ") 
         ret+="+"; 
       else if(strSpecial.indexOf(chr)!=-1) 
         ret+="%"+c.toString(16); 
       else 
         ret+=chr; 
     } 
   } 
   return ret;


    function change()
    {
document.left.location.href="http://www.google.cn/search?num="+document.getElementById("showNum").value+"&complete=1&hl=zh-CN&newwindow=1&q="+UrlEncode

(document.getElementById("txtInput").value);
        
        document.right.location.href="http://www.sogou.com/web?query="+document.getElementById("txtInput").value+"&num="+document.getElementById

("showNum").value;
        
    }
    function leftNone()
    {
        document.getElementById("leftDiv").style.display="none";
        document.getElementById("rightDiv").style.display="block";
    }
    function rightNone()
    {
        document.getElementById("leftDiv").style.display="block";
        document.getElementById("rightDiv").style.display="none";
    }
    function showAll()
    {
        document.getElementById("leftDiv").style.display="block";
        document.getElementById("rightDiv").style.display="block";
    }
    function keyD()
    {
        
    
        if(event.keyCode==13)
        {            
            this.change();
        }
    
    }
    
    
</script>
</head>
<body>
<center>
  <img src="logo.jpg" align="middle" />
  <input name="txtInput" type="text" id="txtInput" onkeydown="keyD()"  />
  </label>
  <label>
  <input type="button" name="Submit" onclick="change()" value="点此搜索" />
  </label>
  <label> &nbsp;&nbsp;&nbsp;
  <select name="showNum" id="showNum">
    <option value="10" selected="selected">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
    <option value="50">50</option>
    <option value="100">100</option>
  </select>
  </label>
  条
</center>
<table width="100%" height="100%" border="0">
  <tr>
    <td  height="100%" ><div id="leftDiv">
        <iframe src="#" scrolling="auto" name="left" width="100%" height="700px"></iframe>
      </div></td>
    <td width="14px"><div id="menu" style="float:left;">
        <input type="button" style="width:14px;height:30px;" name="button" id="button" onclick="leftNone()" value="<" />
        <br />
        <input type="button" style="width:14px;height:30px;" name="button2" id="button2" onclick="rightNone()" value=">" />
        <br />
        <input type="button" style="width:14px;height:30px;" name="button3" id="button3" onclick="showAll()" value="|" />
      </div></td>
    <td  height="100%"><div id="rightDiv">
        <iframe src="#" scrolling="auto" name="right"  width="100%"  height="700px" ></iframe>
      </div></td>
  </tr>
 </table>
         <center>
        版权所有&nbsp;&nbsp;翻版不追究<br />
        Mgod工作室
    </center> 
</body>
</html>



转载于:https://www.cnblogs.com/mgod/archive/2008/05/11/1192454.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值