-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
63 lines (62 loc) · 1.92 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
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Magic Sandbox Test</title>
<script src="magic-sandbox.js"></script>
<!--
<script src="https://unpkg.com/[email protected]/magic-sandbox.min.js"></script>
-->
</head>
<body>
<script type="template" id="template">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Magic Sandbox Test</title>
</head>
<body>
<h1>HELLO</h1>
<p id="p"></p>
<h4>using XMLHttpRequest</h4>
<pre id="data"></pre>
<h4>using fetch</h4>
<pre id="data-from-fetch"></pre>
<script src="fillParagraph.js"><\/script>
<script>
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
document.getElementById("data").textContent = this.responseText;
};
request.open("GET", "data.csv", true);
request.send(null);
fetch("data.csv")
.then(function(res){ return res.text() })
.then(function(text) {
document.getElementById("data-from-fetch").textContent = text;
});
<\/script>
</body>
</html>
</script>
<iframe id="sandbox"></iframe>
<script>
var template = document.getElementById("template")
.textContent.replace(/\\\//g, "/");
var sandbox = document.getElementById("sandbox");
var files = {
"fillParagraph.js": {
content: "document.getElementById('p').textContent = 'Dynamic';"
},
"data.csv": {
content: "A,B,C\n1,2,3\n4,5,6"
}
};
var source = magicSandbox(template, files);
sandbox.setAttribute("srcdoc", source);
</script>
</body>
</html>