3

How can I set the height for iFrame content when content of the iframe is an asp.net site with master page ?

Does anyone know any jQuery plug in ?

Update This works fine in IE but fails in chrome and firefox

    function resizeFrame(f) {
        f.style.height = f.contentWindow.document.body.scrollHeight + "px";
    }

Calling it on body onload()

body onload="resizeFrame(document.getElementById('MainIFrame'))"

iframe code

        <iframe id="MainIFrame" class="autoHeight" runat="server" marginwidth="0"    style="margin: auto; " 
                frameborder="0" width="100%" scrolling="no" >
                </iframe>
Zeus
  • 3,091
  • 6
  • 47
  • 60

1 Answers1

2

Script Works for all Browsers

<script type="text/javascript" language="javascript">
        function resizeIframe(dynheight) {
            try {
                var f = document.getElementById("autosizeframe");
                document.getElementById("autosizeframe").height = parseInt(dynheight) + 10;
                if (f.contentDocument) {
                    f.height = f.contentDocument.documentElement.scrollHeight + 30; //FF 3.0.11, Opera 9.63, and Chrome
                } else {
                    f.height = f.contentWindow.document.body.scrollHeight + 30; //IE6, IE7 and Chrome

                }
            }

            catch (err) {
                alert('Err: ' + err.message);
                window.status = err.message;
            }
        }

        window.onload = function() {
            var height = document.body.scrollHeight;
            resizeIframe(height);

        };                                

    </script>
Madhu Beela
  • 2,205
  • 16
  • 16