posts - 78,  comments - 48,  trackbacks - 0
正在踌躇的时候发现下面的这段代码,终于得意解决。苦于对js没有足够的熟悉,代码中的具体方法参数还得继续学习,感谢提供代码的朋友。
function SetCwinHeight()
{
var cwin=document.getElementById("cwin");
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}

<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight(this)" frameborder="0" scrolling="no"></iframe>


function SetCwinHeight(obj)
{
  var cwin=obj;
  if (document.getElementById)
  {
    if (cwin && !window.opera)
    {
      if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
        cwin.height = cwin.contentDocument.body.offsetHeight;
      else if(cwin.Document && cwin.Document.body.scrollHeight)
        cwin.height = cwin.Document.body.scrollHeight;
    }
  }
}

引用时
onload="javascript:SetCwinHeight(this)"
posted on 2006-04-27 15:50 黑咖啡 阅读(39266) 评论(13)  编辑  收藏 所属分类: Coding Life

FeedBack:
# re: 困扰多时的Iframe自适应高度终于解决了
2006-06-29 23:42 | Noker
完美Iframe高度自适应代码发布——桑米Noker[原创]
看下我的解决方法吧:)似乎要简单很多!

What's new

1.兼容IE6.0,5.5&Mozilla Firefox&傲游(Maxthon&MyIE2)
 可以覆盖绝大多数用户(IE5.01及Opera下未测试,不过该类用户数很少)
2.去除对DOCTYPE声明的依赖,有无或不同声明皆有相同效果
3.解决Firefox下Iframe高度变化后页面高度无法自动回缩问题
4.代码简洁,直接在Iframe的onload标签中添加代码,无需对被调用页面添加代码
5.其它问题改进及Bug修正

http://www.noker.net/bbs/cgi-bin/topic.cgi?forum=12&topic=147  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2006-06-30 09:39 | 黑咖啡
多谢这位朋友的分享,很不错的代码。谢谢。也希望以后能多多交流!@Noker
  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2008-08-27 11:19 | we2design
好东西,解决不少问题  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-01-12 16:46 | lenyes
非常非常的感谢~~~  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-03-13 17:43 | 汪荣富
太感谢,兄弟!收藏  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-03-28 16:04 | awater
万分感谢,问题终于解决了  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了[未登录]
2009-05-13 14:46 | if
问一下,能跨域自适应高度吗<iframe class="frame_content" name="frame_content" allowTransparency="true" style="" frameborder="0" border="0" marginHeight="0" scrolling="no" src="http://54xing.youlianxi.com/54xing/cardlist.aspx"> 这样写好像不行  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-05-16 22:25 | microji
啥叫自适应?不就是在内容长的时候出现滚动条吗?
为什么要用js,

<table height="200" width="300" cellspacing="0" cellpadding="0" style="border: 1px solid rgb(204, 204, 204);"><tbody><tr><td height="24" id="Micro_1_editor_toolbar" style="border-bottom: 1px solid rgb(204, 204, 204);"/></tr><tr><td height="100%" valign="top"><iframe height="100%" frameborder="0" width="100%" scrolling="no" style="padding: 0pt; overflow-y: auto;" id="Micro_1_editor_iframe" name="Micro_1_editor_iframe" class="editor" src="javascript:;"></iframe></td></tr></tbody></table>  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-08-28 09:39 | cloved
现在不行了.都出到IE8了.  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了[未登录]
2009-10-15 14:54 | terry
Call Ajax method in the iframe,your code can't work  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2009-11-15 20:57 | tianjing
编译出现 CS1026: ) expected
为什么?
  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了
2010-07-07 19:06 | 陈建友
这游戏变态  回复  更多评论
  
# re: 困扰多时的Iframe自适应高度终于解决了[未登录]
2014-04-10 11:24 | asa
推荐个文章,解决iframe自适应高度并决jquery ajax获取数据后高度自适应问题
http://www.suchso.com/projecteactual/jquery-ajax-iframe-resetiframeheight.html  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 

<2014年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

留言簿(2)

随笔分类(67)

文章分类(43)

Good Article

Good Blogs

Open Source

最新随笔

最新评论

阅读排行榜

评论排行榜