常州五颜六色网络技术有限公司 -> 网站建设 -> JavaScript应用:Iframe自适应其加载的内容高度 登录 -> 注册 -> 回复主题 -> 发表主题

阿七 2006-04-04 14:28
main.htm: ]<27Sw&yaG  
;OOj[%.  
<html> |XKOXa3.  
  <head> + a-wv  
    <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> N;-/wip  
    <meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> 3ty4D2y  
    <title>iframe自适应加载的页面高度</title> I&L.;~  
  </head> rO/a,vV  
  fy&#M3UA\U  
  <body> )@}A r  
    <iframe src="child.htm"></iframe> ?gLR<d_  
  </body> Wrmgu}q  
</html> "\}b!gl$8  
a9[mZVMgUK  
child.htm: _ XE;-weE  
>s&XX, w  
<html> A-Mj|V  
<head> r"R(}`<,  
  <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> s(teQ\  
  <meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'> NX?}{'f  
  <title>iframe 自适应其加载的网页(多浏览器兼容)</title> wHx}U M"  
  <script language=javascript> YWEYHr;%^?  
  function iframeAutoFit() o`idg[l.  
  { P{?;T5ap6  
    try 'e F%  
    { _ w/_(k  
      if(window!=parent) w4UD/zO  
      { Q|?'(J+  
      var a = parent.document.getElementsByTagName("IFRAME"); TN5>"? ?"  
        for(var i=0; i<a.length; i++) //author:meizz eNtf#Rqym  
        { rWA6X DM7  
          if(a.contentWindow==window) 80C(H!^  
          { V\0E=M*P  
            var h = document.body.scrollHeight; 8) HBh7/  
            if(document.all) {h += 4;} FQ`(b3.   
            if(window.opera) {h += 1;} ?ty>}.c t  
            a.style.height = h; yNBv-oe5  
          } e!GZSk   
        } 9UV9 h_.x  
      } !}_b|  
    } V43TO  
    catch (ex) S`0NPGn;@[  
    { sf$o(^P9\A  
      alert("脚本无法跨域操作!"); /2xSNalC  
    } A{N\)  
  } <YH=3[  
  if(document.attachEvent) window.attachEvent("onload", iframeAutoFit); \|.7-X  
  else window.addEventListener('load', iframeAutoFit, false); O#)jr-vXdV  
  </script> ^XG*z?Tt  
</head> #Y2i*:<  
<body> 4 j X3lq|  
  <div style="width: 200; height: 400; background-color: yellow"> 3#c3IZ-;  
    iframe 自适应其加载的网页(多浏览器兼容) eklgLU-+fW  
  </div> &l m#  
</body> 2 o4^  
</html>


查看完整版本: [-- JavaScript应用:Iframe自适应其加载的内容高度 --] [-- top --]



Copyright © 2005-2014 5y6s Inc. 苏ICP备05001866号 Powered by PHPWind 5.0.1
Time 0.008642 second(s),query:3 Gzip enabled