-
Notifications
You must be signed in to change notification settings - Fork 867
/
Copy pathpostMessageTest.html
116 lines (107 loc) · 3.42 KB
/
postMessageTest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Formulator embedded iframe</title>
</head>
<body>
<iframe id="df" src="./index.html" style="width:1500px;height:1000px"></iframe>
<div>
<button onclick="postMessageToIframe()">Post Load Data message to iframe</button>
</div>
<script>
function postMessageToIframe() {
var iframe = document.getElementById('df');
//create 10 rows of fake data objects like cars dataset. make sure not every manufacturer od Toyota
const data = [
{
"manufacturer": "Toyota",
"model": "Corolla",
"year": 2019,
"price": 20000
},
{
"manufacturer": "Toyota",
"model": "Camry",
"year": 2019,
"price": 25000
},
{
"manufacturer": "Toyota",
"model": "RAV4",
"year": 2019,
"price": 30000
},
{
"manufacturer": "Toyota",
"model": "Highlander",
"year": 2019,
"price": 35000
},
{
"manufacturer": "Toyota",
"model": "4Runner",
"year": 2019,
"price": 40000
},
{
"manufacturer": "Ford",
"model": "Fusion",
"year": 2019,
"price": 20000
},
{
"manufacturer": "Ford",
"model": "Focus",
"year": 2019,
"price": 25000
},
{
"manufacturer": "Ford",
"model": "Escape",
"year": 2019,
"price": 30000
},
{
"manufacturer": "Ford",
"model": "Explorer",
"year": 2019,
"price": 35000
},
{
"manufacturer": "Ford",
"model": "Expedition",
"year": 2019,
"price": 40000
}
];
//create a message object to send to the iframe
/* schema is:
interface LoadDataAction extends Action {
actionName: "loadData";
actionParams: {
tableName: string;
table: object[];
}
}
*/
const configMessage = {
actionName: 'setConfig',
actionParams: {
serverUrl: 'http://localhost:5000/',
}
};
iframe.contentWindow.postMessage(configMessage, '*');
const dataMessage = {
actionName: 'loadData',
actionParams: {
tableName: 'cars',
table: data,
}
};
iframe.contentWindow.postMessage(dataMessage, '*');
}
</script>
</body>
</html>