做Web应用开发时,常会发现,iframe 在ie7的高度设置为100%后,而显示时,其高度并不是100%, 而在ie6中却正常显示
那么怎么才能让iframe的高度自适应呢
可以使用js控制iframe的高度
如下代码:
function reSetIframe(){
var iframe = document.getElementById("iframeId");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
获得body的高度,或你想设置的高度,
在iframe的onload事件中调用此方法就可以了。
<iframe src="" id="
iframeId
" width="278" onload="reSetIframe()"> </iframe>