Skip to content

Instantly share code, notes, and snippets.

@getJv
Created October 11, 2020 05:26
Show Gist options
  • Save getJv/964314d457669e4cf012bd22c34f26a5 to your computer and use it in GitHub Desktop.
Save getJv/964314d457669e4cf012bd22c34f26a5 to your computer and use it in GitHub Desktop.
A sample of receiving the window postMessage from host-page
<!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