-Enter a keyword, click on the following search engine links, you can enter the engine page
-If you enter a keyword and then hit enter, the default search engine is used, and each new search engine is selected, the default engine will change
-Automatic memory last used search engine, followed by add *
The source code is as follows, using a variety of IE/FF adaptation methods:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
. normal {font-family: "Verdana", "Arial"; font-size:14px}
. Small {font-family: "Verdana", "Arial"; font-size:12px}
Body {font-family: "Verdana", "Arial"; font-size:14px}
TD {Font-family: "Verdana", "Arial"; font-size:14px}
th {font-family: "Verdana", "Arial"; font-size:15px}
Input {font-family: "Verdana", "Arial"; font-size:14px}
a {text-decoration:underline; Color:blue}
a:link {text-decoration:underline; Color:blue}
a:visited {text-decoration:underline; Color:blue}
a:hover {text-decoration:underline; color:red}
-->
</style>
<title>my portal</title>
<script language= "JavaScript" >
This section makes Firefox also support IE's InnerText method
function Isie () {
if (Window.navigator.userAgent.toLowerCase (). IndexOf ("MSIE") >=1)
return true;
Else
return false;
}
if (!isie ()) {//firefox innertext define
htmlelement.prototype.__definegetter__ ("InnerText",
function () {
var anystring = "";
var ChildS = this.childnodes;
for (Var i=0 i <childS.length; i++) {
if (childs[i].nodetype==1)
AnyString + = childs[i].tagname== "BR"? ' \ n ': childs[i].innertext;
else if (childs[i].nodetype==3)
AnyString + = Childs[i].nodevalue;
}
return anystring;
}
);
htmlelement.prototype.__definesetter__ ("InnerText",
function (stext) {
This.textcontent=stext;
}
);
}
This section makes Firefox's htmlelement have a click Method (add click Methods to HtmlElement in Mozilla)
try {
Create span element So, HtmlElement is accessible
Document.createelement (' span ');
HTMLElement.prototype.click = function () {
if (typeof This.onclick = = ' function ')
This.onclick ({type: ' click '});
};
}
catch (e) {
Alert (' click Method for HtmlElement couldn\ ' t is added ');
}
Add onclick event to Htmlanchorelement
try {
Create a element so this htmlanchorelement is accessible
Document.createelement (' a ');
HTMLElement.prototype.click = function () {
if (typeof This.onclick = = ' function ') {
if (This.onclick ({type: ' click '}) && This.href)
window.open (This.href, this.target this.target: ' _self ');
}
else if (this.href)
window.open (This.href, this.target this.target: ' _self ');
};
}
catch (e) {
Alert (' click Method for Htmlanchorelement couldn\ ' t is added ');
}
Tracking the ENTER key event
function Capturekeys (evt) {
var keycode = Evt.keycode? Evt.keycode:
Evt.charcode? Evt.charCode:evt.which;
if (keycode = = 13) {
Cancel key:
if (Evt.preventdefault) {
Evt.preventdefault ();
}
var dq = getcookie (' Default-engine ');
if (dq = null) dq = "Baidu_txt";
Submit_query (DQ);
return false;
}
return true;
}
Cookie function function
function GetCookie (cookiename)
{
var cookiestring = Document.cookie;
var start =cookiestring.indexof (cookiename+ ' = ');
if (start = = 1)
return null;
Start + = cookiename.length + 1;
var end = Cookiestring.indexof ('; ', start);
if (end = = 1)
Return unescape (cookiestring.substring (start));
Return unescape (cookiestring.substring (start,end));
}
function Setcookie (cookiename, Cookievalue)
{
var expires = new Date ();
Expires.settime (Expires.gettime () + 3*30*24*60*60*1000); 3 months
Document.cookie = cookiename + ' = ' + Escape (cookievalue) + '; expires= ' +expires.togmtstring ();
}
function Removecookie (cookiename)
{
var expires = new Date ();
Expires.settime (Expires.gettime ()-1);
Document.cookie = cookiename + ' =fooxxx;expires= ' +expires.togmtstring ();
}
function $ (ID) {
return document.getElementById (ID);
}
Mode object, suitable for use under Ie,firefox firebug
function Dumpobject (obj)
{
var temp= "";
for (x in obj)
Temp = + x + ":" + obj[x] + "\ n";
var popup = Window.createpopup ();
Popup.document.body.innerHTML = ' <textarea rows=30 cols=40> ' + temp + ' </textarea> ';
Popup.show (document.body, MB, n,);
}
Multiple query engine request dispatch
function Submit_query (t_query)
{
var keyword = document.getElementById ("keyword");
var MyLink = document.getElementById ("MyLink");
var loc = "";
Switch (t_query)
{
Case "Baidu_txt":
LOC = "http://www.baidu.com/s?wd=" + keyword.value;
Break
Case "Baidu_img":
LOC = "http://image.baidu.com/i?ct=201326592&lm=-1&tn=baiduimagenojs&pv=&word=" + Keyword.value + " &z=0&pn=0&rn=16&cl=2 ";
Break
Case "Yodao_txt":
LOC = "http://www.yodao.com/search?q=" + encodeURI (keyword.value) + "&ue=utf8&keyfrom=web.index";
Break
Case "Yodao_img":
LOC = "http://image.yodao.com/search?q=" + encodeURI (keyword.value) + "&ue=utf8&keyfrom=image.index";
Break
Case "Yodao_dict":
LOC = "http://dict.yodao.com/search?q=" + encodeURI (keyword.value) + "&ue=utf8&keyfrom=dict.index";
Break
Case "Yodao_blog":
LOC = "http://blog.yodao.com/search?q=" + encodeURI (keyword.value) + "&ue=utf8&keyfrom=blog.top";
Break
Case "Iask_ditu":
loc = "http://ditu.iask.com/a/r.php?cl= Beijing &key=" + keyword.value;
Break
Case "VERYCD":
LOC = "http://www.verycd.com/search/folders/" + encodeURI (keyword.value);
Break
Case "Google_txt":
LOC = encodeURI ("http://www.google.com/search?hl=en&q=" + keyword.value + "&btng=google+search");
Break
Case "Yahoo_txt":
LOC = "http://search.yahoo.com/search?p=" +encodeuri (keyword.value) + "&vc=&fr=yfp-t-501&toggle=1& COP=MSS&EI=UTF-8&FP_IP=CN ";
Break
Case "Trans_en":
LOC = "http://209.85.171.104/translate_c?hl=en&sl=en&tl=zh-CN&u=http://" + Keyword.value + "/&usg= Alkjrhijpevzuxptrhdj94k1u9wo8x7s8g ";
Break
Case "Google_code":
LOC = "http://www.google.com/codesearch?q=" + keyword.value + "&hl=en&btng=search+code";
Break
Case "Google_scholar":
LOC = "http://scholar.google.com/scholar?q=" + keyword.value + "&hl=en&lr=&btng=search";
Break
}
Setengine (T_query);
Setcookie (' Default-engine ', t_query);
Mylink.href= Loc;
Mylink.click ();
}
function Getdefaultengine ()
{
var dq = getcookie (' Default-engine ');
if (dq = null) dq = "Baidu_txt";
return DQ;
}
function Setdefaultengine ()
{
var old_e = Getdefaultengine ();
if ($ (old_e). Innertext.indexof (' * ') < 0)
$ (old_e). innertext = $ (old_e). innertext + ' * ';
}
function Setengine (new_e)
{
var old_e = Getdefaultengine ();
if ($ (old_e). Innertext.indexof (' * ') >= 0)
$ (old_e). innertext = $ (old_e). Innertext.replace (' * ', ');
if ($ (new_e). Innertext.indexof (' * ') < 0)
$ (new_e). innertext = $ (new_e). innertext + ' * ';
Setcookie (' Default-engine ', new_e);
}
</script>
<body onload= ' setdefaultengine () ' >
<table border= "0" width= "100%" >
<tr><td>
<a href= "http://www.google.com" id= "MyLink" target= "_blank" >Search:</a>
<input type= "text" name= "keyword" size= "id=" keyword "onkeypress=" return Capturekeys (event); " >
<a href= "#" id= ' Baidu_txt ' onclick= "submit_query (' Baidu_txt ')" > Baidu </a>
<a href= "#" id= ' Google_txt ' onclick= "submit_query (' Google_txt ')" >Google</a>
<a href= "#" id= ' Yodao_txt ' onclick= "submit_query (' Yodao_txt ')" > Youdao </a>
<a href= "#" id= ' Yodao_blog ' onclick= "submit_query (' Yodao_blog ')" > Blog </a>
<a href= "#" id= ' Google_code ' onclick= "submit_query (' Google_code ')" > Code </a>
<a href= "#" id= ' google_scholar ' onclick= "submit_query (' Google_scholar ')" > Thesis </a>
<a href= "#" id= ' baidu_img ' onclick= "submit_query (' baidu_img ')" > Hundred map </a>
<a href= "#" id= ' yodao_img ' onclick= "submit_query (' yodao_img ')" > Map </a>
<a href= "#" id= ' yodao_dict ' onclick= "submit_query (' yodao_dict ')" > Dictionary </a>
<a href= "#" id= ' Iask_ditu ' onclick= "submit_query (' Iask_ditu ')" > Map </a>
<a href= "#" id= ' VERYCD ' onclick= "submit_query (' VERYCD ')" >CD</a>
<a href= "#" id= ' Yahoo_txt ' onclick= "submit_query (' Yahoo_txt ')" >Yahoo</a>
<a href= "#" id= ' trans_en ' onclick= "submit_query (' trans_en ')" > translation </a>
</td></tr>
</table>
</body>