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

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

    I found this resizer to work better:

    function resizer(id)
    {
    
        var doc = document.getElementById(id).contentWindow.document;
        var body_ = doc.body;
        var 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).height = height;
        document.getElementById(id).width = width;
    
    }
    

    Note the style object is removed.

提交回复
热议问题