0

I found the solution here How to auto shrink iframe height dynamically?


I'm trying to Iframe a forum and i need to autosize increasing and decreasing the size of Iframe.

Now i have this:

   <script language="JavaScript" type="text/javascript">
    <!--
    function autoResize(id){
        var newheight;
        var newwidth;

        if(document.getElementById){
            newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
            newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
        }

        document.getElementById(id).height= (newheight) + "px";
        document.getElementById(id).width= (newwidth) + "px";
    }
    //-->
    </script>
    <iframe frameborder="0" height="200px" id="iframe1" marginheight="0" onload="autoResize('iframe1');" src="/forum" width="100%"></iframe>

But this code only increase the size and i need also decrease the size.

Thanks.

Community
  • 1
  • 1
Snowmane
  • 1
  • 2
  • I found the solution here: http://stackoverflow.com/questions/20505038/how-to-auto-shrink-iframe-height-dynamically – Snowmane Jan 29 '14 at 11:41

1 Answers1

1

Try using offsetHeight, rather than scrollHeight.

You might find this library useful, as it also detects a few different events that can cause you to need to resize your iFrame.

https://github.com/davidjbradshaw/iframe-resizer

David Bradshaw
  • 11,859
  • 3
  • 41
  • 70