Skip to content

Instantly share code, notes, and snippets.

@AlexVegner
Last active March 21, 2023 16:10
Show Gist options
  • Save AlexVegner/3471d71c174ccd528442f9b4834d916d to your computer and use it in GitHub Desktop.
Save AlexVegner/3471d71c174ccd528442f9b4834d916d to your computer and use it in GitHub Desktop.
Catch message from iframe
python3 -m http.server 8080
python3 -m http.server 8081
<script>
setTimeout(function() {
window.parent.postMessage({
type:"pin-change-success",
},"*");
}, 2000);
setTimeout(function() {
window.parent.postMessage({
type:"pin-change-failure",
},"*");
}, 4000);
</script>
<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