asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
<iframe  name="ifrm"  id="frm"  src="yourPage.asp"><iframe>  
<button  onclick="frm.style.height=document.ifrm.document.body.clientHeight">  
让iframe高度适应其内叶面高度</button>  
 
---------------------------------------------------------------  
 
1.htm的代码:  
<iframe  src=2.htm  id=ifrm></iframe>  
 
2.htm的代码:  
<script>  
function  resize()  
{parent.document.all.ifrm.height=document.body.scrollHeight;}  
</script>  
<body  onload="resize()">  
</body>
 
用iframe模拟frame子页.htm  
<html>  
<head>  
   <meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312'>  
   <meta  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com'>  
   <title>iframe  自适应其加载的网页(多浏览器兼容)</title>  
   <script  language=javascript>  
   function  iframeAutoFit()    //author:  meizz(梅花雪  20041225)  
   {  
       if(self!=top  &&  window.name=="MzMain")  //这个  name  对应的是  iframe  的  name  
       {  
           var  iframe  =  parent.document.getElementById(window.name);  
           if(iframe)  
           {  
               iframe.parentNode.style.height  =  iframe.style.height;  
               iframe.style.height  =  10;  
               var  h  =  document.body.scrollHeight;  
               var  minimalHeight  =  parseInt((window.screen.width*11)/16,  10)  -  280;  
               h  =  h<minimalHeight  ?  minimalHeight  :  h;  
               if(window.navigator.appName  ==  "Microsoft  Internet  Explorer"  
                   &&  iframe.frameBorder=="1")  h  +=  4;  
               iframe.parentNode.style.height  =  iframe.style.height  =  h;  
           }  
           else  alert("Iframe's  id  unequal  to  iframe's  name!");  
       }  
   }  
   if(document.attachEvent)  window.attachEvent("onload",  iframeAutoFit);  
   else  window.addEventListener('load',  iframeAutoFit,  false);  
   </script>  
</head>  
<body>  
   <span  style="width:  300;  height:  400;  background-color:  yellow">  
       iframe  自适应其加载的网页(多浏览器兼容)  
   </span>  
</body>  
</html>
posted on 2006-04-03 15:30 汪杰 阅读(238) 评论(0)  编辑 收藏 引用 所属分类: javascripthengxing网站js
只有注册用户登录后才能发表评论。

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 459276
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜