ITeye博客

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

leyoo · 2011-06-10 10:51 · javascript · Web前端 · Markdown

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();
}

评论(1)

  1. #1 楼 · menghuannvxia · 2015-04-02 11:03

    哇塞,学习了,多谢

评论功能维护中,当前仅展示历史评论。