lfzxs

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) ;
    }

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案