Resizing an iframe based on content

后端 未结 21 2798
南方客
南方客 2020-11-21 07:40

I am working on an iGoogle-like application. Content from other applications (on other domains) is shown using iframes.

How do I resize the iframes to fit the heigh

21条回答
  •  情深已故
    2020-11-21 08:02

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

    css:

    iframe {border:0; overflow:hidden;}
    

    javascript:

    $(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.

提交回复
热议问题