I have 1 iframe which includes another iframe it and I want to auto height both frames whenever any activity peform in the iframe it load the new page and auto height according to the 2nd (inner iframe)

the code which i am currenlty using in main page and in 1st iframe is as follow please check and help me thank you

<script language="javascript" type="text/javascript">

  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';



Recommended Answers

All 3 Replies


Javascript Code

<script language="javascript">

    function sizeToMyContent( ifRef, setW, setH, fMargin ) { //alert(ifRef);
        var ifDoc, margin = typeof fMargin === 'number' ? fMargin : 6; 
        try { 
            ifDoc = document.getElementById(ifRef).contentWindow.document.documentElement;
        catch( e ) { 
            ifDoc = null;
        if( ifDoc ) {    
            if( setH ) {
                document.getElementById(ifRef).height = ifDoc.scrollHeight + margin + "px"; 
            if( setW ) {
                document.getElementById(ifRef).width = ifDoc.scrollWidth + margin + "px";


<iframe id="Iframe2" name="thisframe" src="filename.html" width="750px" onload="sizeToMyContent(this.id, false, true);"></iframe>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.