父页面iframe高度自动适应子页面iframe高度

function initParentHeight()
{
var div = window.parent.document.getElementById('mainFrame');
div.style.height=window.document.body.scrollHeight||window.document.body.offsetHeight+5;
}

function SetWinHeight(obj)
{
  var win=obj;
   if (win && !window.opera)
   {
     if (win.contentWindow && win.contentWindow.document.body.offsetHeight)   //ie  8
     {
        var height;
        try{
var bheight=win.contentWindow.document.body.scrollHeight;
var dheight=win.contentWindow.document.documentElement.scrollHeight;
    height=Math.max(bheight,dheight);
}catch(ex){}
       win.style.height = height;
     }
     else if(win.Document && win.Document.body.scrollHeight)//ie  6
     {
      win.style.height = win.Document.body.scrollHeight;
     }
   }
   initParentHeight();
}


<iframe id="show_detail" onload="Javascript:SetWinHeight(this);" src="businessAction.do?method=init_CZ_details"  width="700" name="cz" frameborder="0" scrolling="no" style="overflow-x:hidden; " ></iframe>

你可能感兴趣的:(IE,Opera)