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>

相關文章
相關標籤/搜索