關於Google站內搜尋
網站需要做站內搜尋,Google提供了這個服務,從google 的網站上拷回了以下程式碼:
<!-- SiteSearch Google -->
<form method=get action="http://www.google.com/search">
<table bgcolor="#FFFFFF"><tr><td>
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_40wht.gif"
border="0" alt="Google"></a>
</td>
<td>
<input type=text name=q size=31 maxlength=255 value="">
<input type=hidden name=ie value=GB2312>
<input type=hidden name=oe value=GB2312>
<input type=hidden name=hl value=zh-CN>
<input type=submit name=btnG value="Google 搜尋">
<font size=-1>
<input type=hidden name=domains value="YOUR DOMAIN NAME"><br>
<input type=radio name=sitesearch value=""> 搜尋WWW
<input type=radio name=sitesearch value="YOUR DOMAIN NAME" checked> 搜尋YOUR DOMAIN NAME
</font>
</td></tr></table>
</form>
<!-- SiteSearch Google -->
由於趕時間,把最後改正後的程式碼貼在此處,備忘。
<%--Google搜尋--%>
<div class="square_bottom">
<table bgcolor="#FFFFFF" width="100%">
<tr>
<td>
<input type="text" name="q" id="googlekeyword" size="26" maxlength="255" value="" />
<input type="hidden" name="ie" value="utf-8" />
<input type="hidden" name="oe" value="utf-8" />
<input type="hidden" name="hl" value="us-EN" />
<center><input type="button" name="btnG" onclick="search();" value="Google Search" /></center>
<font size="-1">
<input type="hidden" name="domains" value="
<input type="radio" name="sitesearch" value="www.Mysite.com" checked="checked"
style="display: none;" />
</font>
</td>
</tr>
</table>
<!-- SiteSearch Google -->
<script type="text/javascript">
function search()
{
var url = "http://www.google.com/search?q=";
url = url + $("googlekeyword").value + "&ie=utf-8&oe=utf-8&hl=us-EN&btnG=Google+Search&domains=www.chinafastener.com&sitesearch=www.chinafastener.com";
alert(url);
window.location.href = url;
}
</script>
(主要是碰到了asp.net中的ViewState,和javascript 的Domain的問題。)