在asp.net 頁面中添加google 搜索

1.google api 搜索的調用

應用的js文件是

<script type="text/javascript"

  src="http://www.google.com/afsonline/show_afs_search.js">

</script>

2.初始化變量

<script type="text/javascript">

    var googleSearchIframeName = 'googleSearchUnitIframe';

    var googleSearchFrameWidth = 700;

    var googleSearchFrameborder = 0;

    var googleSearchDomain = 'www.google.com';

</script>

3.返回結果的div

<div id="googleSearchUnitIframe"></div>

4.全部html代碼如下:

View Code
<html>

<head></head>

<body>

    <form method="get" target="_top">

<table border="0" bgcolor="#FFFFFF">

<tr><td nowrap="nowrap" valign="top" align="left" height="32">

</td>

<td nowrap="nowrap">

<input type="text" name="as_q" size="64" maxlength="255" value="" id="sbi" />

<input type="submit" name="sa" value="查詢" id="sbb"></input>

</td></tr>

<tr>

<td>&nbsp;</td>

<td nowrap="nowrap">

<table>

<tr>

<td>

<input type="radio" name="sitesearch" value="" checked id="ss0" />

<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>

<td>

<input type="radio" name="sitesearch" value="sohu.com" id="ss1" />

<label for="ss1" title="Search sohu.com"><font size="-1" color="#000000">搜狐</font></label></td>

<td>

<input type="radio" name="sitesearch" value="cnblogs.com" id="ss2" />

<label for="ss1" title="Search cnblogs.com"><font size="-1" color="#000000">博客園</font></label></td>

</tr>

</table>

<input type="hidden" name="client" value="pub-5243795963266234" />

<input type="hidden" name="forid" value="1" />

<input type="hidden" name="ie" value="UTF-8" />

<input type="hidden" name="oe" value="UTF-8" />

<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:11" />

<input type="hidden" name="hl" value="zh-CN" />

</td></tr></table>

</form>

         <h1 class="title">搜索結果</h1>

  <!-- Google Search Result Snippet Begins -->

<div id="googleSearchUnitIframe"></div>

<script type="text/javascript">

    var googleSearchIframeName = 'googleSearchUnitIframe';

    var googleSearchFrameWidth = 700;

    var googleSearchFrameborder = 0;

    var googleSearchDomain = 'www.google.com';

</script>

<script type="text/javascript"

  src="http://www.google.com/afsonline/show_afs_search.js">

</script>



</body>

</html>

5.使用介面如下:

6.上面 就是google的調用需要用到的東西,下面是要查詢的內容的設置

<form method="get" target="_top">

<table border="0" bgcolor="#FFFFFF">

<tr><td nowrap="nowrap" valign="top" align="left" height="32">

</td>

<td nowrap="nowrap">

<input type="text" name="as_q" size="64" maxlength="255" value="" id="sbi" />

<input type="submit" name="sa" value="查詢" id="sbb"></input>

</td></tr>

<tr>

<td>&nbsp;</td>

<td nowrap="nowrap">

<table>

<tr>

<td>

<input type="radio" name="sitesearch" value="" checked id="ss0" />

<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>

<td>

<input type="radio" name="sitesearch" value="sohu.com" id="ss1" />

<label for="ss1" title="Search sohu.com"><font size="-1" color="#000000">搜狐</font></label></td>

<td>

<input type="radio" name="sitesearch" value="cnblogs.com" id="ss2" />

<label for="ss1" title="Search cnblogs.com"><font size="-1" color="#000000">博客園</font></label></td>

</tr>

</table>

<input type="hidden" name="client" value="pub-5243795963266234" />

<input type="hidden" name="forid" value="1" />

<input type="hidden" name="ie" value="UTF-8" />

<input type="hidden" name="oe" value="UTF-8" />

<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:11" />

<input type="hidden" name="hl" value="zh-CN" />

</td></tr></table>

</form>

可以指定申請查詢的語言,返回的語言。

可以指定要查詢的域名。比如上面就指定了3個,一個是web,另一個是搜狐,第三個是博客園。

如果指定了域名,那麼查詢的結果都是指定域名下面的。

<input type="radio" name="sitesearch" value="sohu.com" id="ss1" />
指定搜狐,這個input是name等於sitesearch,value是域名。就可以了。

你可能感兴趣的:(asp.net)