blob: b9f2c1faa7a316a2615b0bb0e9e4c742ab42c455 (
plain)
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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="application/javascript">
"use strict";
window.onload = () => {
opener.postMessage("ready", "*");
};
// eslint-disable-next-line no-shadow
function promiseMessage(source, filter = event => true) {
return new Promise(resolve => {
function listener(event) {
if (event.source == source && filter(event)) {
removeEventListener("message", listener);
resolve(event);
}
}
addEventListener("message", listener);
});
}
// Sends a message to the given target window and waits for the response.
function ping(target) {
let msg = { ping: Math.random() };
target.postMessage(msg, "*");
return promiseMessage(
target,
event => event.data && event.data.pong == msg.ping
);
}
function setFrameLocation(name, uri) {
window[name].location = uri;
}
</script>
</head>
<body>
</body>
</html>
|