iframe自适应宽度和高度,没有滚动条

iframe自适应宽度和高度

支持IE和Firefox浏览器的iframe自适应宽度和高度代码,先确定嵌入页和被嵌入网页加入了以下声明:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    在嵌入页加入以下代码,修改代码中的“test.html”为你的被嵌入页URL即可。

<script type="text/javascript" language="javascript"> 
<!-- 
function TuneHeight(fm_name,fm_id)

    var frm
=document.getElementById(fm_id); 
    var subWeb
=document.frames?document.frames[fm_name].document:frm.contentDocument; 
    
if(frm != null && subWeb != null){
        frm.style.height 
= subWeb.documentElement.scrollHeight+"px";
        
//如需自适应宽高,去除下行的“//”注释即可
        frm.style.width = subWeb.documentElement.scrollWidth+"px";
    }
 
}

 
//-->
</script>

使用方法:
< table style = " height: auto; width: 100%; background-color: #cf0000; " >
                
< tr >
                    
< td style = " width: 10%; height: 100%; background-color: #cf0000; "  valign = " top " >
                        
< iframe  onload = " {TuneHeight('left','left');} "  src = " test1.aspx "   frameborder = " 0 "  style = " border-left-width: thin; border-top-style: none; border-right-style: none;
                            border - bottom - style: none; background - color: #cf0000; "  name= " left "  id= " left "
                            width = " 100% "  height = " 100% "  marginwidth = " 0 "  marginheight = " 0 "  scrolling = " no "  src = " MainMenu.aspx " >
                        
</ iframe >
                    
</ td >
                    
< td style = " background-color: #8c1211; width: 1px " >
                        
|</ td >
                    
< td valign = " top "  style = " width: 90%; height: 100%; background-color: #cf0000; " >
                        
< iframe onload = " {TuneHeight('right','right');} "  src = " test2.aspx "   frameborder = " 0 "  style = " border-left-width: thin; background-color: #cf0000; "
                            name
= " right "  id = " right "  width = " 100% "  height = " 100% "  marginwidth = " 0 "  marginheight = " 0 "
                            scrolling
= " no "   ></ iframe >
                    
</ td >
                
</ tr >
            
</ table >

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值