0

For example, I am trying to iframe the youtube subscription box on the homepage, and the problem is, if I make the iframe really long, then it wastes space, but if I make the size I want, then if the user clicks the "load more videos" button, then it gets cut off. So is there any way to make the iframe (or any alternatives) be a percentage of the size, or dynamically change when the page changes?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Sean
  • 8,401
  • 15
  • 40
  • 48

1 Answers1

1

Create a file and call it iframe.html

<html>
<head>
<script type="text/javascript"></span>
    function autoIframe(frameId){
        try{
            frame = document.getElementById(frameId);
            innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;

            if (innerDoc == null){
                            // Google Chrome
                frame.height = document.all[frameId].clientHeight + document.all[frameId].offsetHeight + document.all[frameId].offsetTop;
            }
                    else{
                    objToResize = (frame.style) ? frame.style : frame;
                    objToResize.height = innerDoc.body.scrollHeight + 18;
                    }
        }

        catch(err){
                alert('Err: ' + err.message);
            window.status = err.message;
        }
    }
    </script>
</head>
<body>
    <iframe id="tree" name="tree" src="tree.html" onload="if (window.parent &amp;&amp; window.parent.autoIframe) {window.parent.autoIframe('tree');}"></iframe>
</body>
</html>  

Now create an html page called tree.html and put some dummy content in it.Make sure that the iframe.html and the tree.html are in the same directory. Open the .html files in browser and you will observe the o/p.

Some more useful links :

Community
  • 1
  • 1
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164