iframe 高度由里面的内容自动撑起

<iframe src="xxxx.html" style="width:100%;" frameborder="no" scrolling="no"></iframe>

frameborder 是否显示边框,

scrolling 是否有滚动条,

在xxxx.html中 ,

    
    parent.document.querySelectorAll("iframe")[0].height = 0;
    parent.document.querySelectorAll("iframe")[0].height = document.body.scrollHeight;
    

即xxxx.html的body高度赋值给父级的iframe高度。

 

附加:

在父级加

document.querySelectorAll("iframe")[0].height = 0;
    document.querySelectorAll("iframe")[0].height = document.querySelectorAll("iframe")[0].contentWindow.document.body.scrollHeight;

未成功。

posted @ 2019-09-09 11:39  犹豫会败北果断不白给  阅读(5824)  评论(0编辑  收藏  举报