Skip to content

Instantly share code, notes, and snippets.

@ay13
Created October 5, 2021 03:56
Show Gist options
  • Save ay13/ab722ad034fb1cd4c54b443d26f508c7 to your computer and use it in GitHub Desktop.
Save ay13/ab722ad034fb1cd4c54b443d26f508c7 to your computer and use it in GitHub Desktop.
// Function to send the size of the page to the parent
const sendSize = function () {
const message = {
iframeResize: {
height: document.body.scrollHeight,
width: document.body.scrollWidth
}
};
window.top.postMessage(message, "*");
};
// Function to send the redirect trigger to the parent
const questionnaireRedirect = function () {
const message = { iframeRedirect: true };
window.top.postMessage(message, "*");
};
window.addEventListener("resize", sendSize, false);
window.addEventListener("load", sendSize, false);
// Can be removed if triggering the redirect function in another way
document
.getElementById("button")
.addEventListener("click", questionnaireRedirect, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment