Iframe元素介绍
<iframe id="iframeC" src="url" frameborder="no" border="0" scrolling="yes" style="width: 100%;height: 100%;"></iframe>
Iframe设置html,body,子元素样式
有时候我们会碰到需要继承父元素宽高的场景,通过给html,body,最外层的div设置宽高100%来继承。

document.getElementById('iframeC').onload = ()=>{
let iframeDocument = document.getElementById("iframeC").contentDocument;
let iframeWindow = document.getElementById('iframeC').contentWindow;
iframeDocument.body.style.width = '100%';
iframeDocument.body.style.height = '100%';
iframeWindow.document.getElementsByTagName('html')[0].style.width = '100%';
iframeWindow.document.getElementsByTagName('html')[0].style.height = '100%';
iframeWindow.document.getElementById('app').style.width = '100%';
iframeWindow.document.getElementById('app').style.height = '100%';
}