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;

未成功。

转载于:https://www.cnblogs.com/html5redbird/p/11490750.html

你可能感兴趣的:(javascript)