forked from eco-monk/appsmith-as-iframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
51 lines (46 loc) · 1.46 KB
/
index.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
45
46
47
48
49
50
51
<html>
<body>
<p>
Send "Parent message" <button onclick="sendMessage('Parent message')">send</button>
Send [ 1, 2, 3 ] <button onclick="sendMessage([1, 2, 3])">send</button>
Send complex array <button onclick="sendComplexMessage(1)">send</button>
</p>
<iframe id="frameEle" src="https://dev.appsmith.com/app/eco-monk-639fd84b326af108c6f82d07" style="height:500px;width:1000px;"></iframe>
<iframe id="frameEle1" src="https://dev.appsmith.com/app/eco-monk-639fd84b326af108c6f82d07" style="height:500px;width:1000px;"></iframe>
<script>
const frameEle = document.getElementById("frameEle");
const frameEle1 = document.getElementById("frameEle1");
function sendMessage(data) {
console.log("send triggered", data);
frameEle.contentWindow.postMessage(data, '*');
frameEle1.contentWindow.postMessage(data, '*');
}
function sendComplexMessage(type) {
let data = "data";
switch (type) {
case 1:
data = [
{
"label": "Blue",
"value": "BLUE"
},
{
"label": "Green",
"value": "GREEN"
},
{
"label": "Red",
"value": "RED"
}
];
break;
}
sendMessage(data);
}
window.addEventListener('message', function (e) {
// Get the sent data
console.log("from iframe", e);
});
</script>
</<body>
</html>