# Script to resize iframe to fit the content it loads?

**URL:** <https://forum.kirupa.com/t/script-to-resize-iframe-to-fit-the-content-it-loads/327184>\
**Category:** web dev\
**Created:** [February 11, 2012, 2:55am UTC](https://forum.kirupa.com/t/script-to-resize-iframe-to-fit-the-content-it-loads/327184 "2012-02-11T02:55:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zenor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/zenor/32/3634_2.png) [@Zenor](https://forum.kirupa.com/u/Zenor)\
**Post date:** [February 11, 2012, 2:55am UTC](https://forum.kirupa.com/t/script-to-resize-iframe-to-fit-the-content-it-loads/327184/1 "2012-02-11T02:55:16Z")

</div>

Hello,

I am still trying to find a method to be able to dynamically resize the iframe to fit the height of the html it loads.

Each html I have created has a different height.  
I tried this script:

```auto
<script type="text/javascript">function iSize(){
document.getElementById('mainFrame').height = document.getElementById('mainFrame').contentWindow.document.body.scrollHeight + "px";
}
</script>

```

The issues I found:

- Chrome(latest): It doesn’t work
- IE 8: It works…
- Firefox(latest): It works…

Any suggestions? I’ve been working on this for days…:d:
