Iframe自适应高度_ie_firefox下都可用

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>iframe</title>
  6. </head>
  7. <body>
  8. <script type="text/javascript">
  9. function SetCwinHeight(){
  10.   var bobo=document.getElementById("bobo"); //iframe id
  11.   if (document.getElementById){
  12.    if (bobo && !window.opera){
  13.     if (bobo.contentDocument && bobo.contentDocument.body.offsetHeight){
  14.      bobo.height = bobo.contentDocument.body.offsetHeight;
  15.     }else if(bobo.Document && bobo.Document.body.scrollHeight){
  16.      bobo.height = bobo.Document.body.scrollHeight;
  17.     }
  18.    }
  19.   }
  20. }
  21. </script>
  22. <iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="http://bbs.yooge.net"></iframe>
  23. 演示分割***************************************************************
  24. </body>
  25. </html>
复制代码
更简单的方法:
  1. <iframe name="main" marginwidth="0"  marginheight="0" src="<?=$abouturl?>" frameborder="0" width="100%" scrolling="no" height="100%" onload="this.height=this.contentWindow.document.body.scrollHeight"></iframe>
复制代码