Home > Article > Web Front-end > js method to realize automatic adaptive height of iframe_javascript skills
The example in this article describes the method of realizing automatic adaptive height of iframe in js. Share it with everyone for your reference. The details are as follows:
When writing web pages, it is often necessary to automatically scale the iframe height. If a list is embedded in the ifram, then after adding data and refreshing the list, the iframe height will automatically extend. After deleting the data, the iframe height should be automatically shortened.
Copy the next piece of code to the html or jsp page where the iframe is located. Just call this function after the 73a6ac4ed44ffec12cee46588e518a5e tag.
<script type="text/javascript"> autoAdjustWindow(); </script> <script type="text/javascript"> //自动调整iframe的高度,自适应树的展开和收缩 function autoAdjustWindow(){ try{ window.frameElement.height=document.body.scrollHeight; window.frameElement.parentElement.height=document.body.scrollHeight; window.frameElement.width=document.body.scrollWidth; window.frameElement.parentElement.width=document.body.scrollWidth; }catch(e){ } } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.