iframe在div中如何自适应高度

div设置了高度自适应,但是在div里面插入一个iframe,用js使iframe获取到div的高度,但是对iframe不起作用
你们说的都不行吖,我说的是div是自适应高度的,让div的高度iframe的高度变化,我已经给iframe设置了宽度是100%,框架的高度是多少,让div随着iframe的高度变化。div中的iframe是一个搜索操作,搜索出来的结果有时候会很多。

//window.onresize表示窗口触发时间的时候执行

//两个函数,用闭包包裹起来()()

window.onload=function(){

(window.onresize=function(){

//获取可见宽度

var width=document.documentElement.clientWidth-180;//180为左边的div的大小

//获取可见高度

var height=document.documentElement.clientHeight-80;//80为头部的div的大小可自己修改

//如果有宽度就给值,

if(width>=0){

document.getElementById('main').style.width=width+'px';

}

if(height>=0){

document.getElementById('sidebar').style.height=height+'px';

document.getElementById('main').style.height=height+'px';

}

})()};

扩展资料:

//设置iframe的高度

function resizeFrameHeight() {

$('.tab_iframe').css('height', document.documentElement.clientHeight - 118);

$('md-tab-content').css('left', '0');

}

window.onresize = function () {

resizeFrameHeight();

initScrollShow();

initScrollState();

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-11-22
<iframe scrolling="no" name="aa" frameborder="0" src="bb.html" onload="this.height=0;var fdh=(this.Document?this.Document.body.scrollHeight:this.contentDocument.body.offsetHeight);this.height=(fdh>700?fdh:700)"></iframe>

iframe高度自适应,700为自己设定的iframe高度最低值,高度小于700的将以700显示,大于700将以div自身高度来显示。iframe高度最低值可以自己修改本回答被提问者和网友采纳
第2个回答  2010-01-13
<!-- 框架高度自适应 -->
<iframe id="mainframe" name="mainframe" src="smb010201.aspx" frameBorder="0" width="100%" scrolling="no" height="100%"
onload="document.all('mainframe').style.height=mainframe.document.body.scrollHeight+30;"> </iframe>

我测试过,完全可以用的
第3个回答  2010-01-11
Iframe高度自适应
<iframe id="iFrame1" name="iFrame1" width="952" onload="this.height=iFrame1.document.body.scrollHeight" scrolling="no" frameborder="0" src="asdf.html"></iframe>
第4个回答  2012-11-05
marginwidth='0' marginheight='0' frameborder='0'
相似回答