div中的iframe怎样根据内容自适应高度

html:
<div id="content">
<iframe src="首页.html" name="center_iframe" frameborder="0" scrolling="no" id="c_iframe"></iframe>
</div>

CSS:
#content{
height:auto;
width:auto;
line-height: 1.5em; /*行间距*/
padding:10px; /*内边距设置*/
}

#content iframe{
height:auto;
width:100%;
}

不知道该怎么给iframe根据内容自动调节高度,不知道该怎么用js来设置,求大神指点

第1个回答  2017-12-08
<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高度最低值可以自己修改追问

不好用呢....我用的DreamWeaver 8,iframe 没有onload属性,写在里也运行不出来...

相似回答