-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
38 lines (37 loc) · 1.35 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>跨域POST消息发送</title>
<script type="text/JavaScript">
// const HOST = 'http://192.168.0.156:5500/';
// const page = `${HOST}/bi-service/api/file/index.html`;
// sendPost 通过postMessage实现跨域通信将表单信息发送到 moweide.gitcafe.io上,
// 并取得返回的数据
function sendPost() {
// 获取id为otherPage的iframe窗口对象
var iframeWin = document.getElementById("otherPage").contentWindow;
// 向该窗口发送消息
iframeWin.postMessage({
"type": "change_color",
"payload": {
"id": "004",
"color": "0xFF00FF"
}
},
'http://127.0.0.1:9000');// 这里是 child页面的域名
}
// 监听跨域请求的返回
window.addEventListener("message", function(event) {
console.log(event, event.data);
}, false);
</script>
</head>
<body>
<textarea id="message"></textarea>
<input type="button" value="发送" onclick="sendPost()">
<iframe
src="http://127.0.0.1:9000" id="otherPage" style="height: 900px;width: 900px"></iframe>
</body>
</html>