-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
50 lines (41 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
<!DOCTYPE html>
<html>
<head>
<title>iFrame Host</title>
<link href="index.css" rel="stylesheet">
</head>
<body>
<div id="iframe_container" class="container">
<h1>iFrame Host</h1>
<!-- <iframe onload="init_iframe()" id="receiver" src=""></iframe> -->
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
let iframe_container = document.getElementById("iframe_container");
window.addEventListener('message', receiveMessage, false);
function receiveMessage(event){
console.log("Received something from embedded iFrame: " + event.origin);
if(event.origin !== "https://iframehost.pages.dev")
return;
console.log("Setting value to local storage: " + event.data);
localStorage.setItem("cookie_value", event.data);
}
// A function to handle sending messages.
function init_iframe() {
var iframe = document.createElement('iframe');
iframe.onload = function() {
const cookie_value = localStorage.getItem("cookie_value");
console.log("Attempting to initialize iframe value with local storage: " + cookie_value);
if(cookie_value != null) {
this.contentWindow.postMessage(cookie_value, '*');
}
};
iframe.src = 'https://iframehost.pages.dev';
iframe.id = 'receiver';
iframe_container.appendChild(iframe);
}
init_iframe();
});
</script>
</body>
</html>