iframe高度自适应

父窗口    
<!-- 页面 -->
<div class="customerPool panel" id="js-customerPool" style="overflow:hidden;">
<div class="row">
<!-- 左边内容 -->
<div class="col-md-8">
<iframe src="{:url('work/list')}" frameborder="0" id="leftiframe" name="leftiframe"></iframe>
</div>
<!-- 右边内容 -->
<div class="col-md-4" style="border-radius:4px;">
<iframe src="{:url('work/search')}" frameborder="0" id="rightiframe" name="rightiframe"></iframe>
</div>
</div>
</div>
<!-- 页面 -->
<include file="public@mfooter" />
<script>
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
//iframeWin.document.body.scrollTop = 0;
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
//if(iframeWin.document.documentElement)iframeWin.document.documentElement.scrollTop = 0;
}
};
window.onload = function () {
setIframeHeight(document.getElementById('leftiframe'));
setIframeHeight(document.getElementById('rightiframe'));

};
</script>


子窗口
<body onload="parent.document.getElementById('leftiframe').height= this.document.body.scrollHeight; ;">
 
posted @ 2020-02-20 09:11  飞鹰之歌  阅读(146)  评论(0)    收藏  举报