How to change height of iframe based on dynamic conent within the iframe?

后端 未结 5 1143
攒了一身酷
攒了一身酷 2021-02-03 15:07

I have an iframe that has dynamic content. If the answers specific questions, additional information displays (hidden div becomes visible). I\'d like the height of the iframe

5条回答
  •  忘了有多久
    2021-02-03 15:30

    Does this work for you?

    http://jsfiddle.net/PmBrd/1/

    Code:

    var iframe = document.getElementById("ifr").contentWindow;
    
    iframe.$(".toggle_div").bind("change", function () {
        $("#ifr").css({
            height: iframe.$("body").outerHeight()
        });
    });
    

    Since you mentioned they are in the same domain, it's just a matter of doing something similar with your real app.

提交回复
热议问题