-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathiframe.content.html
123 lines (105 loc) · 2.86 KB
/
iframe.content.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
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<title>Web APIs Bluetooth Example</title>
<link type="text/css" rel="stylesheet" href="./css/fonts.css" />
<link type="text/css" rel="stylesheet" href="./css/style.css" />
<style>
body {
background-color: #80808029;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
margin:0;
}
/*
.web-api-cnt {
width: 500px;
background: transparent;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
.web-api-card {
border-radius: 2px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.33);
background-color: white;
margin:4px;
}
.web-api-card-head {
text-align: center;
border-bottom-width:1px;
border-bottom-color:gray;
border-bottom-style:solid;
font-size: 24px;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
border-top-color:green;
border-top-style:solid;
font-weight: 600;
}
.web-api-card-body {
text-align: center;
font-size: 21px;
padding-bottom: 5px;
}
button {
background-color: green;
color: white;
padding: 6px 12px;
font-size: 14px;
margin-bottom: 0;
border-radius: 4px;
background-image: none;
border: 1px solid transparent;
}
audio {
width:100%;
height:inherit;
}
@media(max-width:500px) {
.web-api-cnt {
width: 100%;
}
}
*/
</style>
<body>
<div class="web-api-cnt">
<div class="web-api-card">
<div class="web-api-card-head">
Running inside an <i>iframe</i>
</div>
<div class="web-api-card-body">
<div id="iframeDisplayMsg">
</div>
<div>
<input placeholder="Type message.." id="iframeInput" />
</div>
<div>
<button onclick="sendMsgiframe()">Send Msg from <i>iframe</i></button>
</div>
</div>
</div>
</div>
</body>
<script>
var port2
const l = console.log
window.addEventListener("message", function(e) {
l(e)
port2 = e.ports[0]
port2.onmessage = onMessage
})
function onMessage(e) {
const newHTML = "<div>"+e.data+"</div>"
iframeDisplayMsg.innerHTML = iframeDisplayMsg.innerHTML + newHTML
}
function sendMsgiframe(){
port2.postMessage(iframeInput.value)
}
</script>
</html>