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

前端 未结 30 2748
旧时难觅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:53

    If the content is just a very simple html, the simplest way is to remove the iframe with javascript

    HTML code:

    Javascript code:

    function removeIframe(obj) {
        var iframeDocument = obj.contentDocument || obj.contentWindow.document;
        var mycontent = iframeDocument.getElementsByTagName("body")[0].innerHTML;
        obj.remove();
        document.getElementsByClassName("iframe")[0].innerHTML = mycontent;
    }
    

提交回复
热议问题