-
-
Save AlexVegner/3471d71c174ccd528442f9b4834d916d to your computer and use it in GitHub Desktop.
Catch message from iframe
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
python3 -m http.server 8080 | |
python3 -m http.server 8081 |
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
<script> | |
setTimeout(function() { | |
window.parent.postMessage({ | |
type:"pin-change-success", | |
},"*"); | |
}, 2000); | |
setTimeout(function() { | |
window.parent.postMessage({ | |
type:"pin-change-failure", | |
},"*"); | |
}, 4000); | |
</script> |
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
<html> | |
<body> | |
<iframe id="origin8081Iframe" src="http://localhost:8081/iframe_contents.html"></iframe> | |
<script> | |
window.addEventListener('message', function(message){ | |
console.log(message) | |
if (message.data.type=="pin-change-success") { | |
//do something | |
} else if (message.data.type=="pin-change-failure") { | |
//do something | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment