//code from http://caibaojian.com/iframe-adjust-content-height.html
<iframe src="backtop.html" frameborder="0" scrolling="no" id="test" οnlοad="this.height=100"></iframe>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("test");
iframe.height = 0; //只有先设置原来的iframe高度为0,之前的iframe高度才不会对现在的设置有影响
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
console.log(height);
}catch (ex){}
}
window.setInterval("reinitIframe()", 200);
</script>
iframe 自适应高度,更改内容时iframe高度怎么根据新的内容高度自动改变
最新推荐文章于 2022-10-14 11:38:16 发布