Skip to content

Instantly share code, notes, and snippets.

@EricSeastrand
Created March 16, 2022 15:03
Show Gist options
  • Save EricSeastrand/61c99bcfcdfaf0aba21d23611d45052e to your computer and use it in GitHub Desktop.
Save EricSeastrand/61c99bcfcdfaf0aba21d23611d45052e to your computer and use it in GitHub Desktop.
{% 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