帝国教程

iframe框架调用高度自适应方法

来源:我爱模版网 作者:终止符 时间:2026-07-08
浏览:9 收藏 点赞(0)
简介:以下代码加入到你想加的帝国cms模板即可 functionreinitIframe(){ variframe=document.getElementById("test"); try{ varbHeight=iframe.contentWindow.document.body.scrollHeight; vardHeight=iframe.contentWindow.document.documentElement.scrollHeight; varheight=Math

以下代码加入到你想加的帝国cms模板即可

<iframe frameborder="0" src="http://www.daixiao360.cn/" class="iframe" frameborder="0" id="test" onload="this.height=100" width="762px"  scrolling="no"></iframe>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("test");
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>
在线
客服