第一种方式 自己计算 不支持跨域的url
<iframe id='iframe' width='100%' onLoad={resizeHeight} src="http://127.0.0.1:8000/testPage" frameBorder='0'></iframe>
使用Iframe标签 onload方法 通过动态计算获取iframe内容高度的函数,此方法兼容性比较好,但仅仅是同源,即url协议、域名、端口号必须和父页面保持一致,所以把它给毙了
const resizeHeight=()=>{
let iframe = document.querySelector('#iframe');
let contentHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
)