原文:http://www.shareme.cn/blog/article.asp?id=332
<script type="text/javascript"> function SetCwinHeight(iframeObj){ if (document.getElementById){ if (iframeObj && !window.opera){ 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> <iframe width="100%" name="frameContent" onload="SetCwinHeight(this)" frameborder="0" src="*"></iframe>
本文介绍了一种使用JavaScript动态调整iframe元素高度的方法。通过监听iframe加载完成事件并获取其内容的实际高度,确保iframe能够自动扩展到适合的高度,避免页面布局错位。此技巧适用于需要嵌入动态内容的场景。
1809

被折叠的 条评论
为什么被折叠?



