在谷歌自定义搜索上使用iframe

时间:2011-11-11 10:46:59

标签: php google-custom-search

我正在使用php创建一个网站,我正在使用谷歌搜索我的网站。因为我正在使用此代码

 <form action="http://192.168.0.113/boobloom/site/search.php" name="search"  id="cse- search-box" >
   <input type="hidden" name="cx" value="018095423333672301222:n5ebktimfxc" />
   <input type="hidden" name="cof" value="FORID:9" />
   <input type="hidden" name="ie" value="UTF-8" />
   <div class="txt-box"><input type="text" name="q"  /></div>
  <div class="boob-img">
  <input type="image" src="images/boob-img.jpg" name="sa" value="Submit"  /></div>
 </form>
 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-    search-box&lang=en"></script>

但现在我的要求是在iframe的新页面上显示结果。 我之前从不使用Iframe。 我怎么能这样做?提前谢谢..

最后,我从Google自定义搜索引擎中获取了代码,并将结果放在一个页面中,并且其工作正确 但是IFrame的高度太高了..

  <script type="text/javascript">
            var googleSearchIframeName = "cse-search-results";
            var googleSearchFormName = "cse-search-box";
            var googleSearchFrameWidth = 600;
            var googleSearchDomain = "www.google.com";
            var googleSearchPath = "/cse";
        </script>

   <script type="text/javascript" src="www.google.com/afsonline/show_afs_search.js"></script>

我尝试将FrameWidth变量更改为较低的值,但它仍然无效。我可以这样做吗?

var googleSearchFrameHeight = 300;

1 个答案:

答案 0 :(得分:0)

自从我使用iFrames以来已经有一段时间了,所以这可能会有点错误。需要一些修改,但试试这个:

<form action="http://www.google.com/search" target="iframe" method="get" onSubmit="Gsitesearch(this)">
     <input name="q" type="hidden" />
     <input name="qfront" type="text" /> 
  <input type="image" src="images/boob-img.jpg" value="Submit" />

然后iFrame看起来像这样:

<iframe name="iframe" src="" />

基本上,给iFrame一个名称值&amp;让URL或表单操作以它为目标。

希望这有帮助!