iframe 设置iframe高度

设置兄弟iframe的高度 son1.html <html> <script> function test() { alert(1); alert(parent.document.body.scrollHeight); alert(parent.tt2.document.body.scrollHeight);  parent.document.getElementById("tt2").height=800; } </script>    <body>     <h1 id="myH1"> <input type="button" onclick="test()"/>    </body>   </html> son1.html <html>    <body>     <h1 id="myH1">hello,son2  2 2  2 2 </h1>    </body>   </html> father.html <html>    <body>     <Iframe name="tt1" src="son1.html" id="tt1" width="250" height="200" scrolling="no" frameborder="1" ></iframe>         <Iframe name="tt2" src="son2.html" id="tt2" width="250" height="200" scrolling="no" frameborder="1"></iframe>  <h1 id="myH2">hello,my wife</h1>    </body>   </html> 引用点别人的东西 /**  * iframe高度处理  * @author zxub 2006-09-29  */ /**  * 设置iframe高度等于内部页面高度,用于内部页面  */  function setParentHeight(_iframeId) {         if (parent.setIFrameHeight) return;          if (window.addEventListener) //firefox     {                var _action=function()         {                         var _iframe=parent.document.getElementById(_iframeId);             if (!_iframe) return;             _iframe.height=_iframe.contentDocument.body.offsetHeight+16;         }            window.addEventListener("load", _action, false);     }     else if (window.attachEvent) //IE     {         var _action=function()         {             if (!parent.document.getElementById(_iframeId)) return;             parent.document.getElementById(_iframeId).height=document.body.scrollHeight;         }         window.attachEvent("onload", _action);     } } /**  * 设置iframe高度等于内部页面高度,用于父级页面  */ function setIFrameHeight(_iframeId) {         if (window.addEventListener) //firefox     {                   var _action=function()         {                    var _iframe=document.getElementById(_iframeId);             if (!_iframe) return;             _iframe.height=_iframe.contentDocument.body.scrollHeight;             _iframe.onload=function()             {                 this.height=this.contentDocument.body.offsetHeight+16;             }         }         window.addEventListener("load", _action, false);     }     else if (window.attachEvent) //IE     {         var _action=function()         {                     if (!document.getElementById(_iframeId)) return;             document.getElementById(_iframeId).height=document.frames[_iframeId].document.body.scrollHeight;             document.getElementById(_iframeId).onreadystatechange=function()             {                 if (this.readyState=="complete")                 {                     this.height=document.frames[_iframeId].document.body.scrollHeight;                 }             }         }         window.attachEvent("onload", _action);     } } 父子之间传值 一  父到子  直接访问dom对象就ok了 二 子到父 parent.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值