在IFRAME要包含的页面中引用下面的JS就可以解决问题,我测试过了,没有问题。
Code
1<script language="javascript" type="text/javascript">function iframeAutoFit()
2{
3var ex;
4try
5{
6if(window!=parent)
7{
8var a = parent.document.getElementsByTagName("IFRAME");
9for(var i=0; i<a.length; i++)
10{
11if(a[i].contentWindow==window)
12{
13var h1=0, h2=0;
14if(document.documentElement && document.documentElement.scrollHeight)
15{
16h1=document.documentElement.scrollHeight;
17}
18if(document.body) h2=document.body.scrollHeight;
19
20var h=Math.max(h1, h2);
21if(document.all) {h += 4;}
22if(window.opera) {h += 1;}
23a[i].style.height = h +"px";
24}
25}
26}
27}
28catch (ex){}
29}
30if(document.attachEvent)
31{//IE/opera
32window.attachEvent("onload", iframeAutoFit);
33window.attachEvent("onresize", iframeAutoFit);
34}
35else
36{//Mozilla/Firefox
37window.addEventListener('load', iframeAutoFit, false);
38window.addEventListener('resize', iframeAutoFit, false);
39}
40</script>
41
1<script language="javascript" type="text/javascript">function iframeAutoFit()
2{
3var ex;
4try
5{
6if(window!=parent)
7{
8var a = parent.document.getElementsByTagName("IFRAME");
9for(var i=0; i<a.length; i++)
10{
11if(a[i].contentWindow==window)
12{
13var h1=0, h2=0;
14if(document.documentElement && document.documentElement.scrollHeight)
15{
16h1=document.documentElement.scrollHeight;
17}
18if(document.body) h2=document.body.scrollHeight;
19
20var h=Math.max(h1, h2);
21if(document.all) {h += 4;}
22if(window.opera) {h += 1;}
23a[i].style.height = h +"px";
24}
25}
26}
27}
28catch (ex){}
29}
30if(document.attachEvent)
31{//IE/opera
32window.attachEvent("onload", iframeAutoFit);
33window.attachEvent("onresize", iframeAutoFit);
34}
35else
36{//Mozilla/Firefox
37window.addEventListener('load', iframeAutoFit, false);
38window.addEventListener('resize', iframeAutoFit, false);
39}
40</script>
41