iframe自适应高度和宽度

iframe自适应高度和宽度可以通过onload事件来操作,如:

<iframe id="iframe-5566" name="iframe-5566" frameborder="0" width="100%" height="98%" style="display:none" onload="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) ;
    }

 

posted on 2015-12-24 11:03  fengz  阅读(533)  评论(0)    收藏  举报

导航