Skip to content


站内搜索代码乱码问题

使用搜索引擎来进行站内搜索往往比自己编写的站内搜索更高效,有利于搜索引擎收录,并且不占用网站服务器的资源,近日我也在我的博客上加上了google的站内搜索,但是从google上直接取的代码放在我网站上比例不怎么好看,就从网上找代码DIY一下,发现网上提供的代码都是针对GB2312的,而utf-8格式的网站使用会显示乱码?

下面把网上通用的代码发出来

google站内搜索代码 GB2312格式

<!–Google站内搜索开始–>
<form method=get action=”http://www.google.com/search“>
<input type=text name=q>
<input type=submit name=btnG value=”Google 搜索”>
<input type=hidden name=ie value=GB2312>
<input type=hidden name=oe value=GB2312>
<input type=hidden name=hl value=zh-CN>
<input type=hidden name=domains value=”www.iewb.net“>
<input type=hidden name=sitesearch value=”www.iewb.net“>
</form>
<!–Google站内搜索结束–>
百度站内搜索代码 GB2312格式

<!–Baidu站内搜索开始–>
<form action=”http://www.baidu.com/baidu“>
<input type=text name=word>
<input type=”submit” value=”Baidu 搜索”>
<input name=tn type=hidden value=”dywb”>
<input name=cl type=hidden value=”3″>
<input name=ct type=hidden value=”2097152″>
<input name=si type=hidden value=”www.iewb.net“>
</form>
<!–Baidu站内搜索结束–>

google的代码如果想UTF-8可用的话,需要把

<input type=hidden name=ie value=GB2312>改成<input type=hidden name=ie value=UTF-8>

百度的UTF-8我用的是 

<form action=”http://www.baidu.com/baidu” target=”_blank”>
    <input type=”hidden” name=”ie” value=”UTF-8″ /> <input type=”text” name=”word” /> <input type=”submit” value=”Baidu 站内” /> <input name=”tn” type=”hidden” value=”dywb” /> <input name=”cl” type=
    “hidden” value=”3″ /> <input name=”ct” type=”hidden” value=”2097152″ /> <input name=”si” type=”hidden” value=”www.iewb.net” />
</form>

 如果搜索的时候需要在新窗口显示,在需要在链接后面加上 target=”_blank”

最后一个代码我已经加上了,用的时候直接替换网址就可以。

随机文章

所属分类 技术文章.

文章标签 , , .

原创文章转载请注明,转载自:启光博客[http://www.iewb.net]

原文链接: http://www.iewb.net/index.php/qg/336.html


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. 网管一号 评论

    老大,怎么使用啊?、。。。。。



欢迎点评

or, reply to this post via trackback.