Skip to content

Commit f3a60da

Browse files
committed
crossdomain postMessage testing
1 parent 9f6fdca commit f3a60da

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

static/iframeposttest.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>aegewg</title>
7+
</head>
8+
<body>
9+
10+
<input type="text" id="url" placeholder="url">
11+
<button id="post">post msg</button>
12+
13+
<script>
14+
15+
const post = document.getElementById('post');
16+
const url = document.getElementById('url');
17+
18+
const gaga = document.createElement('iframe');
19+
gaga.src = "./iframereceivetest.html";
20+
gaga.width = 600;
21+
gaga.height = 500;
22+
document.body.appendChild(gaga);
23+
24+
url.onchange = () => {
25+
gaga.src = url.value;
26+
};
27+
28+
post.onclick = () => {
29+
gaga.contentWindow.postMessage({
30+
joe: 'oh my goodnees'
31+
}, "*");
32+
};
33+
34+
</script>
35+
36+
</body>
37+
</html>

static/iframereceivetest.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
11+
<script>
12+
13+
window.onmessage = (e) => {
14+
const element = document.createElement('p');
15+
element.innerText = `${JSON.stringify(e.data)}`;
16+
document.body.appendChild(element);
17+
};
18+
19+
</script>
20+
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)