首页 > 编程 > JS > 正文

js操作iframe的src的例子

2020-09-19 11:12:13
字体:
来源:转载
供稿:网友

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表