Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had the problem with the issue how to stretch IFRAME to 100% height depending on the content size in IFRAME. I found out 1 trick here. And all has been working properly in the test page (almost empty page whith this iframe only). But when I inserted this code into page with MasterPage I got an error: Microsoft JScript runtime error: 'document.frames[...].document' is null or not an object. What to do next? How to fix this problem?

The suggested solution I found out earlier here:
<script type="text/javascript">
        function getElement(aID) {
            return (document.getElementById) ?
            document.getElementById(aID) :

document.all[aID];
        }

        function getIFrameDocument(aID) {
            var rv = null;
            var frame = getElement(aID);
            // if contentDocument exists, W3C 

            //compliant(e.g.Mozilla)
            if (frame.contentDocument)
                rv = frame.contentDocument;
            else // bad Internet Explorer  ;)
                rv = document.frames[aID].document;
            return rv;
        }

        function adjustMyFrameHeight() {
            var frame = getElement("frmLection");
            var frameDoc = getIFrameDocument("frmLection");
            frame.height = frameDoc.body.offsetHeight;
        }
    </script>


and HTML content:

<iframe id="frmLection" frameborder="0" width="100%" scrolling="no">
                        src="Lection1.html" runat="server">
                    </iframe>


Could somebody give me some advice? Thanks in advance.
Posted

1 solution

Pavel,

You need to send the client side id of the IFrame tag, generally the client id changes for the controls when rendered to browser based on the page design. Check for the resulting iframe id in the 'View Source' of the page in the browser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900