iframe根据子页面自动调整大小

iframe根据子页面自动调整大小

 //iframe高度自适应

  function IFrameReSize(iframename) {html

  var pTar = document.getElementById(iframename);post

  if (pTar) {  //ffurl

  if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {htm

  pTar.height = pTar.contentDocument.body.offsetHeight;blog

  } //ieget

  else if (pTar.Document && pTar.Document.body.scrollHeight) {iframe

  pTar.height = pTar.Document.body.scrollHeight;it

  }io

  }function

  }

  //iframe宽度自适应

  function IFrameReSizeWidth(iframename) {

  var pTar = document.getElementById(iframename);

  if (pTar) {  //ff

  if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {

  pTar.width = pTar.contentDocument.body.offsetWidth;

  }  //ie

  else if (pTar.Document && pTar.Document.body.scrollWidth) {

  pTar.width = pTar.Document.body.scrollWidth;

  }

  }

  }

  使用方法以下:

  <iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'></iframe>

相关文章
相关标签/搜索