-
Notifications
You must be signed in to change notification settings - Fork 4
/
iframe.html
44 lines (39 loc) · 1.11 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
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>post-messenger - iframe</title>
</head>
<body>
<div id="root">
<pre id="list"></pre>
<div>
<input type="button" value="Once" onclick="javascript: onceListener()" />
<input type="button" value="On" onclick="javascript: onListener()" />
<input type="button" value="Off" onclick="javascript: offListener()" />
<input type="button" value="Send" onclick="javascript: sendMessage()" />
</div>
</div>
<script src="../dist/post-messenger.min.js" type="application/javascript"></script>
<script type="application/javascript">
var pm = new PostMessenger('uniqueId', window.parent);
function listener(message) {
const r = document.querySelector('#list');
console.log(message);
r.innerHTML = r.innerHTML + '\n' + message;
}
function onceListener() {
pm.once('iframe.*', listener);
}
function onListener() {
pm.on('iframe.*', listener);
}
function offListener() {
pm.off('iframe.*', listener);
}
function sendMessage() {
pm.send('iframe.msg', new Date() + ', Hello world.');
}
</script>
</body>
</html>