-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
42 lines (34 loc) · 1.05 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
<html>
<head>
<style>
/* you can style your program here */
</style>
</head>
<body>
<main></main>
</body>
<script type="text/javascript" src="elm.js"></script>
<script>
var app = Elm.Main.init({ node: document.querySelector('main') })
app.ports.execJsonp.subscribe(function(url) {
execJsonp(url);
});
var execJsonp = function(url) {
// Execute the URL by creating the script DOM element
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = url;
// Insert the element, which executes the script
var tag = document.getElementsByTagName('script')[0];
tag.parentNode.insertBefore(script, tag);
// Remove the temp element from the DOM, to avoid DOM bloat
// You should be able to do this right away, without affecting JSONP execution
script.parentNode.removeChild(script);
};
// JSONP callback; name must match what is defined in the execJsonp URL
function jsonpCallback(data) {
app.ports.jsonpCallback.send(data);
};
</script>
</html>