Adjust width and height of iframe to fit with content in it

前端 未结 30 2743
旧时难觅i
旧时难觅i 2020-11-22 02:09

I need a solution for auto-adjusting the width and height of an iframe to barely fit its content. The point is that t

30条回答
  •  余生分开走
    2020-11-22 02:31

    If the iframe content is from the same domain this should work great. It does require jQuery though.

    $('#iframe_id').load(function () {
        $(this).height($(this).contents().height());
        $(this).width($(this).contents().width());
    });
    

    To have it resize dynamically you could do this:

    
    
    

    Then on the page that the iframe loads add this:

    
    

提交回复
热议问题