Autofit height iframe

iframe with animated gif to show while loading content, when iframe is fully loaded, it will resizes itself to fit content.
two parts, the HTML having the iframe, and then the jscript to act when iframe is fully loaded.
Used here since May 2023

CodeFunctionName
What is this?

Public

Tested

Original Work

RelatedCodes_Block        = ""
RelatedCodes_Block        = RelatedCodes_Block & " <div class=""row"" > <div class=""col p-0"" >"
RelatedCodes_Block        = RelatedCodes_Block & ""
RelatedCodes_Block        = RelatedCodes_Block & " <style >"
RelatedCodes_Block        = RelatedCodes_Block & "#loadinggif{position:absolute;z-index:999;}"
RelatedCodes_Block        = RelatedCodes_Block & "#loadinggif div{display:table-cell;width:950px;height:250px;background:#000;text-align:center;vertical-align:middle;}"
RelatedCodes_Block        = RelatedCodes_Block & " </style >"
RelatedCodes_Block        = RelatedCodes_Block & " <div id=""loadinggif"" > <img src=""" & Folderimg & "_load123.gif"" / > </div >"
RelatedCodes_Block        = RelatedCodes_Block & " <iframe src=""/1Place/Part-Code-iFrame.asp?RelatedCodesToCodeID=" & ThisCodeID & "&RecentCodesFromDeveloper=" & ThisUserID & "&RandomCodes=4"" height=""400"" width=""100%"" frameborder=""0"" scrolling=""no"" onload=""resizeIframe(this)"" > </iframe >"
RelatedCodes_Block        = RelatedCodes_Block & " </div > </div >"
RelatedCodes_Block        = RelatedCodes_Block & ""


// jscript
// To be called by iframe of Related codes (Part-Code-iFrame.asp) in single code page (Part-CodeItem-v2.asp)
function resizeIframe(obj) {
    document.getElementById('loadinggif').style.display='none';
    obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
}

Views 71

Downloads 12

CodeID
DB ID