Home > Article > Web Front-end > Example of how to implement iframe adaptive height using JS
The example in this article describes the method of implementing iframe adaptive height in JS. Share it with everyone for your reference, the details are as follows:
<iframe id="mainFrame" name="mainFrame" src="/zwgk/hsearchview" width="740" frameborder="0" scrolling="no" scrolling="no" frameborder="0" > </iframe>
<script type="text/javascript" language="javascript"> function reinitIframe(){ var iframe = document.getElementById("mainFrame"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; }catch (ex){} } window.setInterval("reinitIframe()", 100); </script>
I hope this article will be helpful to everyone in JavaScript programming.
For more examples of JS methods to implement iframe adaptive height, please pay attention to the PHP Chinese website for related articles!