Iframe dynamic size

by dshilkret

HTML

<div id="myDiv" class="flex" dsstyle="width:100%;height:300px;">
<div class="flex-grow">


<iframe id="iFrameID" onload="iframeLoaded()" frameborder="0" src="https://dtecho365.sharepoint.com/:x:/r/sites/ServiceNowDev1/_layouts/15/Doc.aspx?sourcedoc=%7B70893b8f-ea17-4227-a415-c817a99aed40%7D&action=embedview" width="100%" scrolling="no" Content-Security-Policy: sandbox;></iframe>
</div>
</div>

JavaScript

function iframeLoaded() {
     var iFrameID = document.getElementById('iFrameID');
     if (iFrameID) {
         // here you can make the height, I delete it first, then I make it again                                iFrameID.height = "";
         //iFrameID.height = document.getElementById('iFrameID').contentWindow.document.body.scrollHeight +  "px";
iFrameID.height = document.getElementById('myDiv').scrollHeight +  "px";

         console.log(iFrameID.height);
     }
 }