-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathdynamic.html
More file actions
110 lines (102 loc) 路 3.36 KB
/
Copy pathdynamic.html
File metadata and controls
110 lines (102 loc) 路 3.36 KB
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
<!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 dynamically</title>
</head>
<body>
<script>
const table = [
{
"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
}
];
const embedPromise = new Promise((resolve, reject) => {
const embedIframe = document.createElement('iframe');
embedIframe.style.height = '700px';
embedIframe.style.width = 'calc(100% - 4px)';
document.body.appendChild(embedIframe);
// Prepare the HTML content with the script tag.
const closeScriptTag = '</'+'script>';
const htmlContent = `
<!DOCTYPE html>
<html>
<body>
<div id="root"></div>
<script src="../dist/DataFormulator.js" defer onload="console.log('my loc'+document.location);parent.frameLoaded()" onerror="parent.frameError()">${closeScriptTag}
</body>
</html>
`;
// Define global functions for onload and onerror events of the script
window.frameLoaded = () => resolve(embedIframe);
window.frameError = () => reject(new Error('Script failed to load'));
// Write the HTML content to the iframe
embedIframe.contentWindow.document.open();
embedIframe.contentWindow.document.write(htmlContent);
embedIframe.contentWindow.document.close();
});
embedPromise.then((embedIframe) => {
embedIframe.contentWindow.postMessage({ actionName: 'setConfig', actionParams: { serverUrl: 'http://localhost:5567' } }, '*');
embedIframe.contentWindow.postMessage({ actionName: 'loadData', actionParams: { tableName: 'FabricTable', table } }, '*');
});
</script>
</body>
</html>