Last active
March 27, 2019 22:32
-
-
Save ilearnjavascript/451ecda2e7c4de2bc9b95a28dac3cb02 to your computer and use it in GitHub Desktop.
plainjs - window.postmessage and iframes - 2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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