您现在的位置是:网站首页> 编程资料编程资料

Iframe自适应其加载的内容高度_经验交流_

2023-05-25 295人已围观

简介 Iframe自适应其加载的内容高度_经验交流_

  
      
         
         
       iframe自适应加载的页面高度  
      

    
        
    


child.htm:

  
  
     
     
   iframe  自适应其加载的网页(多浏览器兼容)  
   
   function iframeAutoFit()
   {
      try
      {
         if(window!=parent)
         {
          var a = parent.document.getElementsByTagName("IFRAME");
            for(var i=0; i            {
               if(a[i].contentWindow==window)
               {
                   var h = document.body.scrollHeight;
                   if(document.all) {h += 4;}
                   if(window.opera) {h += 1;}
                   a[i].style.height = h;
               }
            }
         }
      }
      catch (ex)
      {
         alert("脚本无法跨域操作!");
      }
   }
   if(document.attachEvent)  window.attachEvent("onload",  iframeAutoFit);  
   else  window.addEventListener('load',  iframeAutoFit,  false);  
     
  
  
     
       iframe  自适应其加载的网页(多浏览器兼容)  
   
  
  

相关内容

-六神源码网