-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.html
50 lines (48 loc) · 1.5 KB
/
root.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
<!--
* @Author: caizeyong
* @Date: 2019-11-06 16:44:45
* @Description:
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Root</title>
</head>
<body>
<iframe src="./frameA.html" frameborder="0"></iframe>
<iframe src="./frameB.html" frameborder="0"></iframe>
<button id="btn">load frame c</button>
<script src="./eventBus.js"></script>
<script>
var registed = false
CreatePostMessageEventBus({
success: function () {
registed = true
console.log('注册成功')
},
receive: function (data) {
console.log('接收到数据', data)
if (data.name === 'root_get-frames-count') {
this.send({
name: 'root_frames-count',
count: window.frames.length
})
}
},
request: function (cmd) {
console.log('要求派发事件', cmd)
},
on: ['root_get-frames-count'],
emit: ['root_frames-count']
})
document.querySelector('#btn').addEventListener('click', function () {
var frame = document.createElement('iframe')
frame.src = './frameC.html'
document.body.appendChild(frame)
})
</script>
</body>
</html>