-
Notifications
You must be signed in to change notification settings - Fork 6
/
test2.html
41 lines (33 loc) · 1.05 KB
/
test2.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
<html>
<body>
<div id ='messageout'/>
<script>
"use strict";
function process_message_event(event){
console.log("message received")
console.log(event.data);
if(typeof event.data == "string"){
data = JSON.parse(event.data);
}else{
data = event.data
}
if(event.origin.indexOf(window.location.hostname) == -1){
console.log("failed origin check");
return
}
if(data.hasOwnProperty("url")){
redirectTo(data.url);
}else{
console.log("No url supplied");
}
}
function redirectTo(url){
window.open(url);
}
//window.addEventListener("message", process_message_event);
setTimeout(function(){
window.addEventListener("message", process_message_event);
}, 10);
</script>
</body>
</html>