内嵌框架自适应页面大小 js语句

 

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       
< 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.gif
None.gifframe.htm 内嵌框架页
None.gif
None.gif
< html >   
None.gif
< head >   
None.gif    
< meta   http-equiv ='Content-Type'   content ='text/html;   charset =gb2312' />   
None.gif      
< title > iframe   自适应其加载的网页(多浏览器兼容) </ title >   
ExpandedBlockStart.gifContractedBlock.gif    
< script type ="text/javascript" > dot.gif
InBlock.gif    
<!--
InBlock.gif    
function iframeAutoFit()
ExpandedSubBlockStart.gifContractedSubBlock.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                
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, h3=0, h4=0;
InBlock.gif                        
if(document.documentElement&&document.documentElement.scrollHeight)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                             h1
= document.documentElement.scrollHeight;
InBlock.gif                             h3
= document.documentElement.scrollWidth;
ExpandedSubBlockEnd.gif                         }

InBlock.gif                        
if(document.body) h2=document.body.scrollHeight;h4=document.body.scrollWidth;
InBlock.gif                        
InBlock.gif
InBlock.gif                        
var h=Math.max(h1, h2);
InBlock.gif                        
var h0=Math.max(h3,h4);
InBlock.gif                       
InBlock.gif                         a[i].style.height
= h +"px";
InBlock.gif                         a[i].style.width
= h0 + "px";
ExpandedSubBlockEnd.gif                     }

ExpandedSubBlockEnd.gif                 }

ExpandedSubBlockEnd.gif             }

ExpandedSubBlockEnd.gif         }

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

InBlock.gif    
InBlock.gif    
if(document.attachEvent)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif         window.attachEvent(
"onload",   iframeAutoFit);
InBlock.gif         window.attachEvent(
"onresize",   iframeAutoFit);
ExpandedSubBlockEnd.gif     }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif         window.addEventListener('load',   iframeAutoFit,  
false);
InBlock.gif         window.addEventListener('resize',   iframeAutoFit,  
false);
ExpandedSubBlockEnd.gif     }

InBlock.gif    
//-->
ExpandedBlockEnd.gif
     </ script >   
None.gif
</ head >   
None.gif
< body style ="overflow:hidden;border:0px" >
None.gif    
< table border ="1" width ="200" style ="height: 200px;width:300px;" >
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/hahacjh/archive/2010/05/16/1736575.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值