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

后端 未结 5 1216
攒了一身酷
攒了一身酷 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:42

    may be a bit late, as all the other answers are from 2011 :-) but... here´s my solution. Tested in actual FF, Chrome and Safari 5.0

    $(document).ready(function(){
        $("iframe").load( function () {
            var c = (this.contentWindow || this.contentDocument);
            if (c.document) d = c.document;
            var ih = $(d).outerHeight();
            var iw = $(d).outerWidth();
            $(this).css({
                height: ih,
                width: iw
            });
        });
    });
    

    Hope this will help anybody.

提交回复
热议问题