make iframe height dynamic based on content inside- JQUERY/Javascript

前端 未结 20 2233
情书的邮戳
情书的邮戳 2020-11-22 07:42

I am loading an aspx web page in an iframe. The content in the Iframe can be of more height than the iframe\'s height. The iframe should not have scroll bars.

I have

20条回答
  •  野性不改
    2020-11-22 07:58

    I found the answer from Troy didn't work. This is the same code reworked for ajax:

    $.ajax({                                      
        url: 'data.php',    
        dataType: 'json',                             
    
        success: function(data)
        {
            // Put the data onto the page
    
            // Resize the iframe
            var iframe = $(window.top.document).find("#iframe");
            iframe.height( iframe[0].contentDocument.body.scrollHeight+'px' );
        }
    });
    

提交回复
热议问题