起点设计资源网提供更多的素材下载资源,让你设计工作更方便!
高级搜索 收藏本站 网站地图 RSS订阅 最新专题

HTML|XHTML

HTML|XHTML- iframe的高度随内容的变化而变化的实现方法

『 更新时间:2008-11-16 』『 字体: 』『 作者:佚名 |  来源:68start 』



下面详细介绍了iframe框架高度随内容的变化而变化的代码。大家根据自己的需要提取!

<iframe src="XXX.htm" width="700px" frameborder="0" id="frmsrc" scrolling="no" marginheight="0" onload="AutoIframe()"></iframe>

<script type="text/javascript">
    function AutoIframe()
    {
        if(document.readyState!='complete')
        {
            setTimeout( function(){AutoIframe();},25 );
            return;
        }
        else
        {
          var ifobj=document.getElementById("frmsrc");
字串5

          ifobj.height= ifobj.contentWindow.document.body.scrollHeight;
        }
    }
</script>

//PS: XXX.htm不可跨域

<iframe src="dd.html" id="frmMain" name="frmMain" width="99%" height="100%" frameborder=0 scrolling=no marginHeight=0 marginWidth=0 onload="Javascript:SetWinHeight(this)" ></iframe>

function SetWinHeight(obj)
{
var win=obj;
if (document.getElementById)
{
    if (win && !window.opera)
    {
  if (win.contentDocument && win.contentDocument.body.offsetHeight)
    win.height = win.contentDocument.body.offsetHeight;
  else if(win.Document && win.Document.body.scrollHeight)
    win.height = win.Document.body.scrollHeight;
    }
字串7

}
}