首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Iframe自适应高度统制

2012-11-23 
Iframe自适应高度控制iframe width778 aligncenter height200 idcwin namecwin onloadJ

Iframe自适应高度控制

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

JS代码:
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;    }  }}


在iframe里面显示的页面,还要加点这样的样式控制:
<style type="text/css">        html, body        {            overflow-x: hidden;            overflow: auto;            margin: 0px;            height: 100%;        }    </style>

热点排行