cnblogs 将左侧和包括置顶区域在内的导航区全部放置在一个 <form> 表单中,由于 HTML 中 <form> 不允许嵌套,因此如果我们自己设置 google 搜索的话,会造成 google 搜索所用表单处于 cnblogs 表单的内层,从而失效。
为了解决这个问题,我们只能使用嵌套 iframe 的办法来动态生成一个页面,并利用这个页面实现搜索功能。
将下列代码全部粘贴到后台管理的“选项-配置-公告”文本框内。将其中我的博客地址 http://www.cnblogs.com/qiangsheng/,替换成你自己的博客地址即可。

<script>
document.write(
'<div id="GoogleLayer" style="width: 200; height: 100;">');
document.write(
'<iframe name="GoogleIframe" scrolling="no" frameborder="0" width="100%" height="100%" allowtransparency="true"></iframe></div>');

var SearchGoogle = new SearchGoogle();
writeIframe();

function SearchGoogle() //初始化日历的设置
{
    
this.iframe = window.frames("GoogleIframe"); //日历的 iframe 载体
    this.calendar = getObjectById("GoogleLayer");  //日历的层
}


function getObjectById(id)if(document.all) return(eval("document.all."+ id)); return(eval(id)); }

function writeIframe()
{
    
var strIframe = '<html><head>'
                  
+ '<meta http-equiv="Content-Type" content="text/html; charset=gb2312">'
                  
+ '<link id="rivercast" type="text/css" rel="stylesheet" href="http://www.cnblogs.com/Skins/rivercast/style.css" />'
                  
+ '</head>'
                  
+ '<body bgcolor="transparent" style="background-color: transparent">'
                  
+ '<for' + 'm action="http://www.google.com/search" method="get" target="_top">'
                  
+ '<p><img src="http://www.google.cn/images/google_sm.gif" width="70px" height="30px">'
                  
+ '<table><tr><td>'
                  
+ '<input style="width: 170px; height: 21px" maxlength="255" size="48" name="q"  type="text" />'
                  
+ '<font size="2">'
                  
+ '<br /><input type="radio" value="" name="sitesearch" /> 搜索WWW '
                  
+ '<input type="radio" CHECKED value="http://www.cnblogs.com/qiangsheng/" name="sitesearch" /> 搜索本站</font>'
                  
+ '<br /><input style="width: 105px; height: 23px" type="submit" value="Google 搜索" name="btnG" />'
                  
+ '</td></tr></table>'
                  
+ '</p></for' + 'm></body></html>';
    
with (SearchGoogle.iframe)
    
{
        document.writeln(strIframe);
        document.close();
    }

}

</script>
posted on 2008-04-28 14:52  华亭慧剑  阅读(572)  评论(1编辑  收藏  举报