js操作iframe的src的例子

作者:网络 来源:佚名 更新时间:2008-10-11 11:33:19 点击:

本文详细介绍了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");
           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;
    }
 }
}