Iframe自动适应加载内容高度

最近在做项目的时候,我发现Iframe可以自动适应加载内容高度,觉得挺新奇,想研究一下这段JS。原来是用到meizz(梅花雪)写的JS,真佩服meizz,可以说写JS已经出神入化了。真想认识一下meizz,看能不能通过朋友介绍认识一下,那真是万分荣幸了。好了,该show一下了。

None.gif main.htm:
None.gif
None.gif
< html >   
None.gif    
< head >   
None.gif       
< meta http - equiv = 'Content - Type'  content = 'text / html; charset = gb2312'  />   
None.gif       
< meta  name = 'author' content = 'F.R.Huang(meizz梅花雪) // www.meizz.com' />  
None.gif
        < title > iframe自适应加载的页面高度 </ title >   
None.gif    
</ head >   
None.gif     
None.gif    
< body >
None.gif        
< iframe src = " child.htm " ></ iframe >
None.gif    
</ body >
None.gif
</ html >
None.gif
None.gifchild.htm:
None.gif
None.gif
< html >   
None.gif
< head >   
None.gif    
< meta  http - equiv = 'Content - Type'  content = 'text / html;  charset = gb2312'  />   
None.gif    
< meta  name = 'author'  content = 'F.R.Huang(meizz梅花雪) // www.meizz.com' />  
None.gif
     < title > iframe  自适应其加载的网页(多浏览器兼容) </ title >   
None.gif    
< script type = " text/javascript " >
None.gif    
<!--
None.gif    
function  iframeAutoFit()
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
var ex;
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(window!=parent)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
var a = parent.document.getElementsByTagName("IFRAME");
InBlock.gif                
for(var i=0; i<a.length; i++//author:meizz
ExpandedSubBlockStart.gifContractedSubBlock.gif
                dot.gif{
InBlock.gif                    
if(a[i].contentWindow==window)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
var h1=0, h2=0;
InBlock.gif                        
if(document.documentElement&&document.documentElement.scrollHeight)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            h1
=document.documentElement.scrollHeight;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
if(document.body) h2=document.body.scrollHeight;
InBlock.gif
InBlock.gif                        
var h=Math.max(h1, h2);
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(document.all) dot.gif{h += 4;}
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(window.opera) dot.gif{h += 1;}
InBlock.gif                        a[i].style.height 
= h +"px";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
catch (ex)dot.gif{}
ExpandedBlockEnd.gif    }

None.gif    
if (document.attachEvent)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        window.attachEvent(
"onload",  iframeAutoFit);
InBlock.gif        window.attachEvent(
"onresize",  iframeAutoFit);
ExpandedBlockEnd.gif    }

None.gif    
else
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        window.addEventListener('load',  iframeAutoFit,  
false);
InBlock.gif        window.addEventListener('resize',  iframeAutoFit,  
false);
ExpandedBlockEnd.gif    }

None.gif    
// -->
None.gif
     </ script >   
None.gif
</ head >   
None.gif
< body >
None.gif    
< table border = " 1 "  width = " 200 "  style = " height: 400px; background-color: yellow " >
None.gif        
< tr >
None.gif            
< td > iframe  自适应其加载的网页(多浏览器兼容,支持XHTML) </ td >
None.gif        
</ tr >
None.gif    
</ table >
None.gif
</ body >   
None.gif
</ html >
None.gif

转载于:https://www.cnblogs.com/yolion/archive/2007/08/14/855511.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值