JS代碼如下:
<script type="text/javascript">
function SetWinHeightBySelf(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>
在頁面相應的內嵌框架中使用如下:
<iframe name="frameContent" src="main.html" frameborder="0" width="100%" οnlοad="SetWinHeightBySelf(this);"></iframe>