Skip to content

Instantly share code, notes, and snippets.

@nummi
Created December 1, 2021 21:31
Show Gist options
  • Save nummi/3d836ba05508a1e84e5c1779036e411d to your computer and use it in GitHub Desktop.
Save nummi/3d836ba05508a1e84e5c1779036e411d to your computer and use it in GitHub Desktop.
;(function () {
const on = window.addEventListener
let parent = null
const _post = function () {
parent.postMessage(
{
type: 'FRAME_HEIGHT',
height: document.documentElement.scrollHeight,
},
'*'
)
}
const post = function () {
let timer = null
clearTimeout(timer)
if (parent) {
timer = setTimeout(_post, 250)
}
}
on('message', function (event) {
parent = event.source
post()
})
on('resize', post)
on('load', post)
new MutationObserver(function () {
post()
}).observe(document.querySelector('body'), {
childList: true,
attributes: true,
characterData: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true,
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment