CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  JavaScript

问个问题,关于判断iframe里面页面的高度

楼主ForMyBrian(人~~)2006-02-24 17:17:34 在 Web 开发 / JavaScript 提问

有一iframe在页面a中  
  iframe的src是另一个页面b  
  为了让iframe不出现滚动条  
  我需要在a页面中根据b页面的高度和宽度动态设置iframe的高度和宽度  
  问题在于  
  我需要如何去取得b页面的高度和宽度?  
  不吝赐教,万分感激! 问题点数:100、回复次数:6Top

1 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:19:09 得分 100

如果何能使iframe的大小随着它包含的网页里面的table大小变化而变化?急切!!!  
  A   :  
                   
   
                   
                   
  例如,怎样使iframe的高度和宽度     随着table的高度和宽度     改变而改变?如下:      
   
  Main.htm      
   
  <html>      
   
  <body>      
   
  <div>      
   
  <iframe         name=mm     src=”detail.htm”     width=”变数”     height=”变数”     </iframe>      
   
  </div>      
   
  </body>      
   
  </html>      
   
       
   
  detail.htm      
   
  <html>      
   
  <body>      
   
  <table     width=”变数”     height=”变数”     border=0     bgcolor=red>      
   
  <tr><td></td></tr>      
   
  </table>      
   
  </body>      
   
  </html>      
   
  急切,请高手快指点!!!!      
   
       
   
  ---------------------------------------------------------------      
   
       
   
  main.htm      
   
       
   
  <html>      
   
  <body>      
   
  <div>      
   
  <iframe     id=frmDetail     scrolling=no     name=mm     src="detail.htm"     style="width:expression(this.contentWindow.document.all.tblDetail.width);height:expression(this.contentWindow.document.all.tblDetail.height)"></iframe>      
   
  <button     onclick="with(document.all.frmDetail.contentWindow.document.all.tblDetail){width=offsetWidth+1}">+</button>      
   
  <button     onclick="with(document.all.frmDetail.contentWindow.document.all.tblDetail){width=offsetWidth-1}">-</button>      
   
  </div>      
   
  </body>      
   
  </html>      
   
       
   
  detail.htm      
   
       
   
  <html>      
   
  <body     leftmargin=0     topmargin=0>      
   
  <table     id=tblDetail     width=100     height=100     border=0     bgcolor=red>      
   
  <tr><td></td></tr>      
   
  </table>      
   
  </body>      
   
  </html>      
   
       
   
  ---------------------------------------------------------------      
   
       
   
  稍微变通一下就是啦.      
   
  main.htm      
   
       
   
  <html>      
   
  <body>      
   
  <div>      
   
  <iframe     id=frmDetail     scrolling=no     name=mm     src="tb.htm"     onload="style.width=this.contentWindow.document.all.tblDetail.offsetWidth;style.height=this.contentWindow.document.all.tblDetail.offsetHeight"></iframe>      
   
  </div>      
   
  </body>      
   
  </html>      
   
       
   
       
   
  tb.htm      
   
  <html>      
   
  <body     leftmargin=0     topmargin=0>      
   
  <table     id=tblDetail     width=100     height=100     border=0     bgcolor=red>      
   
  <tr><td>      
   
  dddddddddddddddddddddddddddddddddddddddddddddddddddddddd      
   
  </td></tr>      
   
  </table>      
   
  </body>      
   
  </html>      
   
       
   
  ---------------------------------------------------------------      
   
       
   
  test.asp      
   
  <%      
   
  url=Request.QueryString("url")      
   
  %>      
   
  <body     onload="document.all.ifId.style.width=parseInt(ifId.document.getElementsByTagName('table')[0].width)+20">      
   
  <iframe     name=ifId     id=ifId     src="<%=url%>"></iframe>      
   
  <br>      
   
  <a     href=2.asp?url=1.asp>1.asp</a>      
   
  <br>      
   
  <a     href=2.asp?url=2.asp>2.asp</a>      
   
       
   
  1.asp      
   
  <table     width=500>      
   
  <tr><td>      
   
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa      
   
  </table>      
   
       
   
  2.asp      
   
  <table     width=200>      
   
  <tr><td>      
   
  aaaaaaaaa      
   
  </table>Top

2 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:19:47 得分 0

如何更改<iframe>的高度?急!在线等,高分!  
  A   :  
                   
   
                   
                   
  有这样的代码:      
   
  <iframe     frameborder="0"     scrolling="no"         src="body.htm"     width="778"             height="710"     name="m_body"></iframe>      
   
  如何在body.htm里改变<iframe>的高度!      
   
  ---------------------------------------------------------------      
   
       
   
  <body     onload="parent.document.all.m_body.style.height='4000'">Top

3 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:20:21 得分 0

如何在iframe的name不定时,根据被包含页面大小动态改变iframe的大小?  
  A   :  
                   
                   
                   
  秋水无痕:      
   
  <script     language="javascript">      
   
  function     toppage()      
   
  {                                                      
   
                  if     (self.location!=top.location)frameElement.height=document.body.scrollHeight     +     30;      
   
  }      
   
  </script>      
   
       
   
  <body     onload="toppage()">      
   
       
   
  frameElement地用法,可见      
   
  http://www.blueidea.com/bbs/newsdetail.asp?id=442170      
   
  但frameElement只有在IE5.5以上支持。      
   
       
   
       
   
  根据秋水的提示,我在看了      
   
  http://www.blueidea.com/bbs/newsdetail.asp?id=340771      
   
  后知道了完美的解决办法。      
   
       
   
  <script     language="javascript">      
   
  <!--      
   
  function     toppage()      
   
  {                                                      
   
                          if     (self.location!=top.location)      
   
                          {      
   
                                                  parent.document.all(self.name).height=document.body.scrollHeight     +     30;      
   
                                                                                                       
   
                          }      
   
  }      
   
  -->      
   
  </script>      
   
  <body     onload="toppage()">      
   
       
   
  IE5.0测试通过,IE4没法试了,不过还用IE4的非常少了,基本可以不考虑。Top

4 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:20:43 得分 0

Iframe   自适应其加载的网页高度(多浏览器兼容版)  
  A   :  
                   
                   
                   
  如何在打开这个页面时得到这个页面的高度?      
   
  一个框架面面,包含三个页面      
   
  头,左,右三个页面      
   
  右面的页面是主显示区会有滚动条,如何让整个框架页有滚动条,而不是单个页面出滚动条。      
   
  ---------------------------------------------------------------      
   
       
   
  <html>      
   
  <head>      
   
          <meta     http-equiv='Content-Type'     content='text/html;     charset=gb2312'>      
   
          <meta     name='author'     content='F.R.Huang(meizz梅花雪)//www.meizz.com'>      
   
          <title>用     iframe     模拟     frame     使网架网页能够居中</title>      
   
  </head>      
   
       
   
  <body     topmargin=0     leftmargin=0><center>      
   
  <table     border=0     width=780     height=100%     cellspacing=0     cellpadding=0     align=center>      
   
          <tr><td     width=780     colspan=2     height=100>      
   
                          <iframe     width=100%     height=100%     frameborder=1></iframe>      
   
          </td></tr>      
   
          <tr>      
   
                  <td     width=180>      
   
                          <iframe     width=100%     height=100%     frameborder=1></iframe>      
   
                  </td>      
   
                  <td     width=600     valign=top><div     style="height:     100%">      
   
                          <iframe     width=100%     height=100%     name="MzMain"     frameborder=1      
   
                              id="MzMain"     src="用iframe模拟frame子页.htm"></iframe>      
   
                  </div></td>      
   
          </tr>      
   
  </table>      
   
  </center></body></html>      
   
       
   
       
   
  用iframe模拟frame子页.htm      
   
  <html>      
   
  <head>      
   
          <meta     http-equiv='Content-Type'     content='text/html;     charset=gb2312'>      
   
          <meta     name='author'     content='F.R.Huang(meizz梅花雪)//www.meizz.com'>      
   
          <title>iframe     自适应其加载的网页(多浏览器兼容)</title>      
   
          <script     language=javascript>      
   
          function     iframeAutoFit()         //author:     meizz(梅花雪     20041225)      
   
          {      
   
                  if(self!=top     &&     window.name=="MzMain")     //这个     name     对应的是     iframe     的     name      
   
                  {      
   
                          var     iframe     =     parent.document.getElementById(window.name);      
   
                          if(iframe)      
   
                          {      
   
                                  iframe.parentNode.style.height     =     iframe.style.height;      
   
                                  iframe.style.height     =     10;      
   
                                  var     h     =     document.body.scrollHeight;      
   
                                  var     minimalHeight     =     parseInt((window.screen.width*11)/16,     10)     -     280;      
   
                                  h     =     h<minimalHeight     ?     minimalHeight     :     h;      
   
                                  if(window.navigator.appName     ==     "Microsoft     Internet     Explorer"      
   
                                          &&     iframe.frameBorder=="1")     h     +=     4;      
   
                                  iframe.parentNode.style.height     =     iframe.style.height     =     h;      
   
                          }      
   
                          else     alert("Iframe's     id     unequal     to     iframe's     name!");      
   
                  }      
   
          }      
   
          if(document.attachEvent)     window.attachEvent("onload",     iframeAutoFit);      
   
          else     window.addEventListener('load',     iframeAutoFit,     false);      
   
          </script>      
   
  </head>      
   
  <body>      
   
          <span     style="width:     300;     height:     400;     background-color:     yellow">      
   
                  iframe     自适应其加载的网页(多浏览器兼容)      
   
          </span>      
   
  </body>      
   
  </html>Top

5 楼ForMyBrian(人~~)回复于 2006-02-24 17:22:58 得分 0

顿首  
  谢Top

6 楼ice_berg16(寻梦的稻草人)回复于 2006-02-24 17:24:29 得分 0

在iframe页内  
  window.onload   =function(){  
  parent.document.getElementById("iframeID").width=document.body.scrollHeight;  
  }Top

相关问题

  • !!!!!!!!!!!!!如何判断页面是否在iframe中?》》》》》》》》》》》》》》》》》
  • 如何判断自己的页面被其他站点在iframe中调用?
  • 如何判断自己的页面被其他站点在iframe中调用?
  • 怎样判断页面的iframe中是否存在某个javascript函数?
  • 怎样在框架页面中判断窗口的宽度和高度
  • 谁提供一下iframe高度除页面高度自动调整的代码`
  • 页面高度?
  • 请教一下一个页面如何判断有没有被嵌套在<iframe>中,谢谢。
  • 有办法判断一个IFRAME页面没有被成功加载吗,或者加载出现异常?
  • 求在mozilla下取得iframe内页面的实际高度的方法

关键词

得分解答快速导航

  • 帖主:ForMyBrian
  • superdullwolf

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo