K_Reverter的网页开发记录

要么不做,要么就当作艺术品来做!

导航

[导入]创建高度动态变化的Iframe

iframe,尤其是不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是iframe的大小却不像层那样可以“伸缩自如”,所以带来了使用上的麻烦,给iframe设置高度的时候多了也不好,少了更是不行,现在,我终于知道了让iframe动态体调整高度的方法,主要是以下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,不能丢掉onload属性,当然了,id也必须也函数中的cwin匹配

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

 

这样使用效果确实不错

posted on 2005-06-07 16:49  K_Reverter  阅读(363)  评论(0编辑  收藏  举报