-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
57 lines (56 loc) · 1.43 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<div id="app">
<input type="text" v-model="value"/>
<button @click="setData">SET Data</button>
<button @click="getData">GET Data</button>
<iframe src="https://iframe.test/hub.html" style="display: none;" id="iframe"></iframe>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript"></script>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data() {
return {
value: ''
}
},
methods: {
setData() {
const self = this
const iframe = document.getElementById('iframe')
localStorage.setItem('access_token', this.value)
iframe.contentWindow.postMessage({
action: 'set',
key: 'access_token',
value: self.value
}, '*')
},
getData() {
const self = this
const iframe = document.getElementById('iframe')
iframe.contentWindow.postMessage({
action: 'get',
key: 'access_token'
}, '*')
window.addEventListener('message', function (event) {
const data = event.data
switch (data.action) {
case 'returnData':
self.value = data.value
break
default:
console.log('Cannot get value')
}
})
}
}
})
</script>
</body>
</html>