87,984
社区成员
发帖
与我相关
我的任务
分享iframe.height =200;// 先设置为一个很小的值,如200,让iframe先恢复后重设高度
setTimeout(function(){
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
},100);//防止浏览器优化代码,直接执行这句,所以用计时器延时执行<iframe onload="resetHeight(this)"></iframe>
<script>
function resetHeight(i) {
var h = Math.max(i.contentWindow.document.body.scrollHeight, i.contentWindow.documentElement.body.scrollHeight);
i.style.heigh=h+'px'
}
</script>