简体   繁体   中英

resize iframe internet explorer 9

Trying to create a function that re-sizes iframes at window.onload .

The following works with Fire Fox but not IE 9. After searching I tried a few of the other examples but they mess up the Fire Fox re-size and don't fix the IE 9 re-size.

Any suggestions?

<script type="text/javascript" language="javascript">
  function sizeFrame() {
    var frames = document.getElementsByTagName('iframe'); 
    for (var i = 0; i < frames.length; i++){ 
      var fID     = frames[i].id; 
      var F       = document.getElementById(fID);

      if(F.contentDocument && F.contentDocument.documentElement.scrollHeight) {
        F.height = F.contentDocument.documentElement.scrollHeight+30; //FF 3.0.11, Opera 9.63, and Chrome

      } else if(F.contentDocument && F.contentDocument.documentElement.offsetHeight) {
        F.height = F.contentDocument.documentElement.offsetHeight+30; //standards compliant syntax – ie8

      } else {
        F.height = F.contentWindow.document.body.scrollHeight+30; //IE6, IE7 and Chrome
      }
    }
  }


  window.onload=sizeFrame; 
</script>

I think if you just did

F.contentWindow.document.body.offsetHeight+30;

Rather than the three tests you currently have it would work much better for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM