iframe自适应高度和宽度可以通过onload事件来操作,如:
<iframe id="iframe-5566" name="iframe-5566" frameborder="0" width="100%" height="98%" style="display:none" οnlοad="iframLoad(this)">
</iframe>
function iframLoad(ifm){
try{
$(ifm).height(ifm.contentWindow.document.body.scrollHeight);
$(ifm).width(ifm.contentWindow.document.body.scrollWidth);
}catch(e){
$(ifm).height(320);//默认高度
$(ifm).width(320); //默认宽度
}
}
但是 如果 iframe的高度是动态的呢?...我们可以在子页面内做这样的回调:
function autosize(){
var ifm = parent.document.getElementsByName(window.name)[0];
parent.iframLoad(ifm) ;
}