关于Google站内搜索

来源:互联网 发布:海湾联动编程 编辑:程序博客网 时间:2024/05/17 22:11

网站需要做站内搜索,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="www.Mysite.com" /><br />
                                                <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的问题。)

原创粉丝点击