Home >Web Front-end >JS Tutorial >Example of how to implement iframe adaptive height using JS

Example of how to implement iframe adaptive height using JS

高洛峰
高洛峰Original
2017-01-09 09:05:461039browse

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!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn