您的位置:宽带测速网 > 帝国cms > 帝国cms模板中iframe框架调用高度自适应js方法是什么?

帝国cms模板中iframe框架调用高度自适应js方法是什么?

2025-08-25 08:56来源:互联网 [ ]

用js模板有实现框架自适应高度的方法,代码希望对大家有用。
代码:

<iframeframeborder="0"src="/"class="iframe"frameborder="0"id="test"onload="this.height=100"width="762px"scrolling="no"></iframe><scripttype="text/javascript">functionreinitIframe(){variframe=document.getElementById("test");try{varbHeight=iframe.contentWindow.document.body.scrollHeight;vardHeight=iframe.contentWindow.document.documentElement.scrollHeight;varheight=Math.max(bHeight,dHeight);iframe.height=height;console.log(height);}catch(ex){}}window.setInterval("reinitIframe()",200);</script>
框架的网址可以改成自己的框架地址,也可以放在模板中用标签进行调用视频地址等。