let currentPageHeight = 0;
function submit() {
let viewHeight = document.body.clientHeight;
if (viewHeight !== currentPageHeight) {
currentPageHeight = viewHeight;
setTimeout(() => {
submit();
}, 400);
} else {
window.parent.postMessage(
{
type: "iframeHeight",
viewHeight,
},
"*"
);
}
}
submit();
window.addEventListener("message", function (res) {
const {
data: { type, viewHeight },
} = res;
switch (type) {
case "iframeHeight":
document.querySelector(".iframeWrap").style.height =
viewHeight + "px";
break;
}
});