Created
March 16, 2022 15:03
-
-
Save EricSeastrand/61c99bcfcdfaf0aba21d23611d45052e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% capture iframe_content %} | |
<body onload="resizeIframe()"> | |
{{ bit_widget_html }} | |
</body> | |
{% endcapture %} | |
<script> | |
/* | |
This iframe stuff ended up being unnecessary. | |
But if we did need to isolate the BiT stuff to avoid style conflicts, this would be the only way I think. | |
*/ | |
//loadHtmlContentInsideIframe({{ iframe_content | json }}); | |
function loadHtmlContentInsideIframe(contentHtml) { | |
function resizeIframe() { | |
console.log("Resizing iframe"); | |
var newHeight = iframe.contentDocument.body.scrollHeight; | |
iframe.style.height = parseInt(newHeight,10) + 10 + 'px'; | |
} | |
var iframe = document.createElement("iframe"); | |
iframe.setAttribute('seamless', '') | |
iframe.setAttribute('frameborder', '0') | |
iframe.style.width = '100%'; | |
iframe.style.height = '100%';// This won't really have much effect: height is derived from inner content. See resizeIframe() above. | |
var pageContentContainer = document.getElementById('MainContent') | |
pageContentContainer.appendChild(iframe); | |
var frameDoc = iframe.document; | |
if(iframe.contentWindow) | |
frameDoc = iframe.contentWindow.document; // IE | |
// Write into iframe | |
iframe.contentWindow.resizeIframe = resizeIframe | |
window.addEventListener("resize", resizeIframe) | |
frameDoc.open(); | |
frameDoc.writeln(contentHtml); | |
frameDoc.close(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment