Skip to content

Instantly share code, notes, and snippets.

@sfarthin
Last active August 29, 2015 13:56
Show Gist options
  • Save sfarthin/9140403 to your computer and use it in GitHub Desktop.
Save sfarthin/9140403 to your computer and use it in GitHub Desktop.
Child/Parent frame communication
<button onclick="parent.postMessage('close', '*');">Hide</button>
<!-- http://stackoverflow.com/questions/21931275/hiding-a-div-that-contains-an-iframe/21931547#21931547 -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<div id="myDiv">
<iframe src="childFrame.html" id="frame1"></iframe>
</div>
<script>
window.onmessage = function(e) {
if(e.data == "close") $("#myDiv").toggle();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment