Search results for 'iframe auto resize'. 1 post(s) found.

  1. 2008/05/03 IFRAME Auto Resize in IE, FireFox by Javascript (13)
2008/05/03 08:39

IFRAME Auto Resize in IE, FireFox by Javascript


Here's the simple iframe auto-resize example working on IE, and FireFox.

<iframe id='ifrm'
                frameborder=0
                width=100%
                height=450
                scrolling=no
                src='http://kurapa.com'
></iframe>

<script language='javascript'>

function getDocHeight(doc)
{
  var docHt = 0, sh, oh;
  if (doc.height)
  {
    docHt = doc.height;
  }
  else if (doc.body)
  {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
function getReSize()
{
  var iframeWin = window.frames['ifrm'];
  var iframeEl = window.document.getElementById? window.document.getElementById('ifrm'): document.all? document.all['ifrm']: null;
  if ( iframeEl && iframeWin )
  {
    var docHt = getDocHeight(iframeWin.document);
    if (docHt != iframeEl.style.height) iframeEl.style.height = docHt + 'px';
  }
  else
  { // FireFox
    var docHt = window.document.getElementById('ifrm').contentDocument.height;
    window.document.getElementById('ifrm').style.height = docHt + 'px';
  }
}
function getRetry()
{
    getReSize();
    setTimeout('getRetry()',500);
}
getRetry();
</script>

Trackback 0 Comment 13

Trackback : Cannot send a trackbact to this post.