Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ilearnjavascript/8edbf5e143c962b8f3e85c1997614aac to your computer and use it in GitHub Desktop.
Save ilearnjavascript/8edbf5e143c962b8f3e85c1997614aac to your computer and use it in GitHub Desktop.
plainjs - window.postmessage and iframes - 6.html
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>iframe</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>iframe</h1>
<button>Trigger postMessage</button>
<div id="innerContainer"></div>
</body>
<script>
document.querySelector("button").addEventListener("click", function() {
top.postMessage("message from iframe", 'http://127.0.0.1:8080');
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment