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

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

    all can not work using above methods.

    javascript:

    function resizer(id) {
            var doc = document.getElementById(id).contentWindow.document;
            var body_ = doc.body, html_ = doc.documentElement;
    
            var height = Math.max(body_.scrollHeight, body_.offsetHeight, html_.clientHeight, html_.scrollHeight, html_.offsetHeight);
            var width = Math.max(body_.scrollWidth, body_.offsetWidth, html_.clientWidth, html_.scrollWidth, html_.offsetWidth);
    
            document.getElementById(id).style.height = height;
            document.getElementById(id).style.width = width;
    
        }
    

    html:

    height width

    Env: IE 10, Windows 7 x64

提交回复
热议问题