Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Parent page sends message to iframe const iframe = document.querySelector("iframe"); iframe.contentWindow.postMessage({ action: "resize", height: 300 }, "https://widget.com"); // Inside the iframe — listen for messages window.addEventListener("message", (event) => { if (event.origin !== "https://parent.com") return; // Security check console.log("Received:", event.data); });
Result
Open