One: the ultimate effect
Two: Principle
If you search for "China" in Yahoo, you will get such a list of addresses in the browser's address bar: http://search.cn.yahoo.com/search?ei=gbk&fr=fp-tab-web-ycn&meta= vl%
3dlang_zh-cn%26vl%3dlang_zh-tw&pid=ysearch&source=ysearch_www_hp_button
&p=%d6%d0%b9%fa&submit=
Looks a little messy, simplify: Http://search.cn.yahoo.com/search?&p=%D6%D0%B9%FA
That's the key. Where &P=%D6%D0%B9%FA is the keyword parameter of the search, and%d6%d0%b9%fa is the "China"
URL encoding. OK, all we need to do is construct this code.
Three: URL encoding
The encodeURIComponent () function of JavaScript can do the coding work.
For example, we can use "http://search.cn.yahoo.com/search?&p=" +encodeuricomponent ("China") to complete.
Four: Code
(Click the plus sign to expand)
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Search.aspx.cs" inherits= "Search"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>Search</title>
<script language= "javascript" type= "Text/javascript" >
<! cdata[
function Getencodeofkey ()
{
var strkey = window.document.getElementById ("Text_key"). Value;
Return encodeURIComponent (strkey);
}
function GetUrl (site)
{
var encode=getencodeofkey ();
Web
if (document.getElementById ("Radiobuttonlist_kind_0"). Checked)
{
if (site== "Google")
{
Return "http://www.google.com/search?q=" +encode+ "&ei=utf-8";
}
Else
{
Return "http://search.yahoo.com/search?p=" +encode+ "&ei=utf-8";
}
}
mp3
else if (document.getElementById ("Radiobuttonlist_kind_1"). Checked)
{
if (site== "Google")
{
Return "http://www.google.com/search?q=" +encode+ "MP3" + "&ei=utf-8";
}
Else
{
Return "http://audio.search.yahoo.com/search/audio?&p=" +encode+ "&ei=utf-8";
}
}
Img
else if (document.getElementById ("Radiobuttonlist_kind_2"). Checked)
{
if (site== "Google")
{
Return "http://images.google.com/images?q=" +encode+ "&ei=utf-8";
}
Else
{
Return "http://images.search.yahoo.com/search/images?p=" +encode+ "&ei=utf-8";
}
}
Else
{
Alert ("Err");
}
}
function Button_google_onclick ()
{
window.open (GETURL ("Google"));
}
function Button_yahoo_onclick ()
{
window.open (GETURL ("Yahoo"));
}
]]>
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<br/>
<br/>
<strong><span style= "FONT-SIZE:24PT; Color: #336633 ">search<br/>
</span></strong>
</div>
<br/>
<table style= "left:0px; position:relative; top:0px ">
<tr>
<TD style= "WIDTH:31PX; height:21px ">
<span style= "Font-family:terminal" >Key</span></td>
<TD style= "WIDTH:253PX; height:21px ">
<input id= "Text_key" style= "WIDTH:248PX; Position:relative "type=" text "/></td>
<TD style= "WIDTH:175PX; height:21px ">
<asp:radiobuttonlist id= "Radiobuttonlist_kind" runat= "server" repeatdirection= "Horizontal"
Style= "position:relative" font-names= "terminal" >
<asp:listitem selected= "True" >Web</asp:ListItem>
<asp:ListItem>Mp3</asp:ListItem>
<asp:ListItem>Image</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<TD style= "width:31px" >
</td>
<TD colspan= "2" >
<input id= "Button_google" style= "width:80px; Position:relative "type=" button "value=" Google "onclick=" return Button_google_onclick () "/>
<input id= "Button_yahoo" style= "left: -29px; width:104px; Position:relative "type=" button "
Value= "Yahoo!" onclick= "Return Button_yahoo_onclick ()"/></td>
</table>
<br/>
<asp:hyperlink id= "Hyperlink_home" runat= "Server" navigateurl= "~/default.aspx" style= "position:relative" > Home</asp:hyperlink></form>
</body>