读书人

Iframe自适应高度统制

发布时间: 2012-11-23 22:54:33 作者: rapoo

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>

读书人网 >Web前端

热点推荐