Skip to content

Commit

Permalink
Create iframe.html
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone authored Jun 6, 2024
1 parent 53542ff commit 747d59c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<h3>The message from the parent appears below:</h3>
<div id="message">Please send some message from the input above.</div>
<script>
window.addEventListener("message", function (event) {
document.querySelector("#message").innerText =
typeof event.data === "string"
? event.data
: JSON.stringify(event.data);
});
</script>
<input style="margin-top: 1em" type="text" id="messageText" />
<button id="sendMessage">Send Message to Parent</button>
<script>
var button = document.querySelector("#sendMessage");
button.addEventListener("click", function () {
var message = document.querySelector("#messageText").value;
window.parent.postMessage(message, "*");
});
</script>
</body>
</html>

0 comments on commit 747d59c

Please sign in to comment.