Created
October 11, 2020 05:26
-
-
Save getJv/964314d457669e4cf012bd22c34f26a5 to your computer and use it in GitHub Desktop.
A sample of receiving the window postMessage from host-page
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function () { | |
window.addEventListener("message", (event) => { | |
let iframe = document.querySelector('#my-iframe'); | |
iframe.height = event.data.height; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h2>Host page</h2> | |
<iframe id="my-iframe" width="100%" src="./guestpage.html" frameborder="1"></iframe> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment