Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Last active March 27, 2019 22:31
Show Gist options
  • Save ilearnjavascript/c9095d2d5bb1e74d176372502faac31d to your computer and use it in GitHub Desktop.
Save ilearnjavascript/c9095d2d5bb1e74d176372502faac31d to your computer and use it in GitHub Desktop.
plainjs - window.postmessage and iframes - 1.js
function receiveMessage(event) {
if (event.origin === "http://iframe.com"
&& event.data === "message we expect") {
// execute code
}
}
// event listener for message event
window.addEventListener("message", receiveMessage, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment