feat: broadcast height to parents - useful when iframed

This commit is contained in:
jongomez 2023-11-06 17:08:01 +00:00 committed by Jon
parent 55d4bda014
commit 31c2c9ea91

View File

@ -0,0 +1,23 @@
<script>
function sendHeightToParent() {
const height =
document.documentElement.scrollHeight || document.body.scrollHeight
window.parent.postMessage(
{
type: 'iframeResize',
height: height,
},
'*',
)
}
document.addEventListener('DOMContentLoaded', function () {
// Send initial height.
sendHeightToParent()
// Ensure the interval is set only once.
if (!window.heightIntervalSet) {
window.heightIntervalSet = setInterval(sendHeightToParent, 1000)
}
})
</script>