Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Last active March 27, 2019 22:32
Show Gist options
  • Save ilearnjavascript/451ecda2e7c4de2bc9b95a28dac3cb02 to your computer and use it in GitHub Desktop.
Save ilearnjavascript/451ecda2e7c4de2bc9b95a28dac3cb02 to your computer and use it in GitHub Desktop.
plainjs - window.postmessage and iframes - 2.js
function receiveMessage(event) {
if (event.origin === "http://iframe.com"
&& event.data === "message we expect"
&& event.data.length === 19
&& typeof event.data === 'string') {
// 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