There are a lot of highly adaptive codes for iframes on the Internet, but they are quite messy. This article organizes the following codes based on practicality:
JavaScript part:
Collapse JavaScript Code copy content to clipboard
<script type="text/javascript"> function SetCwinHeight(iframeObj){ if (document.getElementById){ if (iframeObj){ if (iframeObj.contentDocument && iframeObj.contentDocument.body.offsetHeight){ iframeObj.height = iframeObj.contentDocument.body.offsetHeight; } else if (document.frames[iframeObj.name].document && document.frames[iframeObj.name].document.body.scrollHeight){ iframeObj.height = document.frames[iframeObj.name].document.body.scrollHeight; } } } } </script>
html part:
Collapse XML/HTML Code copy content to clipboard
<iframe name="frameContent" src="*" frameborder="0" width="100%" onload="SetCwinHeight(this)"></iframe>
Fill in the address of the iframe page where * is marked. It should be noted that the src address must be under the same website, otherwise a "permission prohibited" error will occur.