iFrame和匹配的侧边栏div高度

时间:2013-06-25 23:26:33

标签: javascript html css

所以我有一个HTML页面。我有一个iframe,当内容加载到它时调整大小,但我有一个侧边栏(div),我需要设置高度等于新的iframe高度。 我为iframe调整大小的javascript是

function setIframeHeight( iframeId ) /** IMPORTANT: All framed documents *must* have a               DOCTYPE applied **/  
{
 var ifDoc, ifRef = document.getElementById( iframeId );

 try
 {   
  ifDoc = ifRef.contentWindow.document.documentElement;  
 }
 catch( e )
 { 
  try
  { 
    ifDoc = ifRef.contentDocument.documentElement;  
   }
  catch(ee)
  {   
  }  
 }

 if( ifDoc )
 {
  ifRef.height = 1;  
   ifRef.height = ifDoc.scrollHeight;

  /* For width resize, enable below.  */

  // ifRef.width = 1;
  // ifRef.width = ifDoc.scrollWidth; 
 }
}

Actualy代码不是我的,是Logic Ali的信用。

1 个答案:

答案 0 :(得分:0)

你需要有一个这样的onResize处理程序。

http://www.w3schools.com/jsref/event_onresize.asp

window.onresize=function(){
    setIframeHeight( iframeId )
};