-Enter a keyword and click the search engine link to go to the search engine page.
-If you enter a keyword and press enter, the default search engine is used. The default search engine is changed for each selected search engine.
-Automatically remembers the search engine used last time, followed *
The source code is as follows:
Copy codeThe Code is as follows:
<Html>
<Head>
<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">
// FireFox also supports the innerText method of IE.
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 the click method (add click method to HTMLElement in Mozilla)
Try {
// Create span element so that 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 be added ');
}
// Add an onclick event to HTMLAnchorElement
Try {
// Create a element so that 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.tar get? This.tar get: '_ self ');
}
Else if (this. href)
Window. open (this. href, this.tar get? This.tar get: '_ self ');
};
}
Catch (e ){
// Alert ('click method for HTMLAnchorElement couldn \'t be added ');
}
// Tracks 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 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 );
}
// Used for Object mode, applicable to firebug in IE and Firefox
Function dumpObject (obj)
{
Var temp = "";
For (x in obj)
Temp + = x + ":" + obj [x] + "\ n ";
Var popup = window. createPopup ();
Popup.doc ument. body. innerHTML = '<textarea rows = 30 cols = 40>' + temp + '</textarea> ';
Popup. show (100,100,300,400, document. body );
}
// 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_schlar ":
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>
</Head>
<Body onload = 'setulultengine () '>
<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 = "20" 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 _ value' onclick = "submit_query ('Google _ shell')"> thesis </a>
<A href = "#" id = 'Baidu _ img 'onclick = "submit_query ('Baidu _ img')"> diagram </a>
<A href = "#" id = 'yodao _ img 'onclick = "submit_query ('yodao _ img')"> illustrated </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>
</Html>