在IFRAME要包含的页面中引用下面的JS就可以解决问题,我测试过了,没有问题。
1
<script language="javascript" type="text/javascript">function iframeAutoFit()2


{3
var ex;4
try5


{6
if(window!=parent)7


{8
var a = parent.document.getElementsByTagName("IFRAME");9
for(var i=0; i<a.length; i++) 10


{11
if(a[i].contentWindow==window)12


{13
var h1=0, h2=0;14
if(document.documentElement && document.documentElement.scrollHeight)15


{16
h1=document.documentElement.scrollHeight;17
}18
if(document.body) h2=document.body.scrollHeight;19

20
var h=Math.max(h1, h2);21

if(document.all)
{h += 4;}22

if(window.opera)
{h += 1;}23
a[i].style.height = h +"px";24
}25
}26
}27
}28

catch (ex)
{}29
}30
if(document.attachEvent)31


{//IE/opera32
window.attachEvent("onload", iframeAutoFit);33
window.attachEvent("onresize", iframeAutoFit);34
}35
else36


{//Mozilla/Firefox 37
window.addEventListener('load', iframeAutoFit, false);38
window.addEventListener('resize', iframeAutoFit, false);39
}40
</script>41
