-
Notifications
You must be signed in to change notification settings - Fork 0
/
iframe.html
32 lines (32 loc) · 1.12 KB
/
iframe.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!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) {
console.log(["github receive",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;
console.log(["github send",event]);
window.parent.postMessage(message, "*");
});
</script>
</body>
</html>