-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathchild.html
76 lines (69 loc) · 2.34 KB
/
child.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Child</title>
<script src="https://unpkg.com/penpal@^5/dist/penpal.min.js"></script>
<style>
html, body {
margin: 0;
overflow: hidden;
}
button, pre {
display: block;
}
</style>
</head>
<body>
<button id="signIn" disabled>Sign in</button>
<button id="signOut" disabled>Sign out</button>
<button id="scrollTop" disabled>Scroll to top</button>
<pre id="url"></pre>
<pre id="token"></pre>
<pre id="profile"></pre>
<script>
const log = (el, info) => el.textContent = typeof info === 'object' ? JSON.stringify(info, null, 4) : String(info);
// Child needs to connect after parent
window.onload = () => {
const connection = Penpal.connectToParent({
methods: {
onShow: () => {
console.log('Im visible');
},
onHide: () => {
console.log('Im hidden');
}
},
timeout: 5000,
debug: true
});
// Enable buttons once connected
connection.promise.then((parent) => {
signIn.onclick = () => parent.signIn();
signOut.onclick = () => parent.signOut();
scrollTop.onclick = () => parent.scrollTop();
signIn.disabled = false;
signOut.disabled = false;
scrollTop.disabled = false;
// Access parent info
Promise.all([
parent.getURL(),
parent.getIMSAccessToken(),
parent.getIMSProfile()
]).then((data) => {
// Log info
console.log(new URL(data[0]));
log(url, data[0]);
log(token, data[1]);
log(profile, data[2]);
// Update parent height to avoid duplicated scrollbar issue
parent.setHeight(`${document.body.scrollHeight}px`);
});
});
};
</script>
<h1>iFrame source file</h1>
<p>Some text in frame: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eleifend ornare purus, vel dapibus augue suscipit in. Nam blandit vitae ante et auctor. Donec placerat egestas posuere. Aliquam erat volutpat. In condimentum massa eu pharetra porta. Nunc tempus massa sit amet nisl posuere sagittis. Mauris sit amet rhoncus neque. Phasellus ut vulputate est, vel auctor metus.</p>
</body>
</html>