javascript - Adjust width height of iframe to fit with content in it -


I need a solution to a height of auto adjusting width and an iframe difficult to fit its content. The point is that width and height can be changed after loading the iframe. I guess I need an event action to deal with the changes in the amplitude of the body contained in the iframe estimates.

  & lt; Script type = "application / javascript" & gt; Function resizeIFrameToFitContent (iFrame) {iFrame.width = iFrame.contentWindow.document.body.scrollWidth; Iframe.height = IFrame contentWindow.document.body.scrollHeight; } Window.addEventListener ( 'DOMContentLoaded', function (e) {var iFrame = document.getElementById ( 'iFrame1'); resizeIFrameToFitContent (iFrame); // Or, to change all iframes Size: var iframes = document.querySelectorAll ( " iframe "); I & lt; iframes.length, (var i = 0 i ++) {resizeIFrameToFitContent (iframes to [i]);}}); & Lt; / Script & gt; & Lt; Iframe src = "usagelogs / default.aspx" id = "iFrame1" & gt; & Lt; / Iframe & gt;  

Comments