js实现iframe动态调整高度的代码

复制代码 代码如下:

  function SetWinHeight(obj)

  {

  var win=obj;

  if (document.getElementById)

  {

  if (win && !window.opera)

  {

  if (win.contentDocument && win.contentDocument.body.offsetHeight)

  win.height = win.contentDocument.body.offsetHeight;

  else if(win.Document && win.Document.body.scrollHeight)

  win.height = win.Document.body.scrollHeight;

  }

  }

  }

  最后,加入iframe,不能丢掉onload属性,当然了,id也必须也函数中的win匹配

  程序代码

  

复制代码 代码如下:

  <iframe width=”778″ align=”center” height=”200″ id=”win” name=”win” onload=”Javascript:SetWinHeight(this)” frameborder=”0″ scrolling=”no”></iframe>