How to set the iframe height & width to 100%

后端 未结 7 1526
礼貌的吻别
礼貌的吻别 2021-01-04 04:19

I am in need of doing the following:

  1. I have a header content which is 70px and an iframe with a wrapper. The height & width of the iframe has to be set to
7条回答
  •  猫巷女王i
    2021-01-04 05:15

    Simple and clean. jQuery is required. Source: https://stackoverflow.com/a/3940802

    Modified a bit

                    function iframeHeight() {
                        var newHeight = $(window).height();
                        var newWidth = $(window).width();
                        var buffer = 100;     // space required for any other elements on the page
                        var newIframeHeight = newHeight - buffer;
    
                        $('iframe.fop').css('height',newIframeHeight).css('width',newWidth);    //this will aply to all iframes on the page, so you may want to make your jquery selector more specific.
                    }
    
                    // When DOM ready
                    $(function() {
                        window.onresize = iframeHeight;
                        iframeHeight();
                    });

提交回复
热议问题