-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify.html
More file actions
executable file
·49 lines (46 loc) · 1.38 KB
/
notify.html
File metadata and controls
executable file
·49 lines (46 loc) · 1.38 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>frame</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
</body>
</html>
<script type="text/javascript">
function parms(opt) {
var QPARM_REG = /([^&=]+)=([^&]*)/g,
pars = location.search.substr(1),
m;
while (m = QPARM_REG.exec(pars)) {
opt[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return opt;
}
function send(){
window.addEventListener('message', function(e) {
var data = e.data;
if(data && data.notification){
localStorage.setItem('notifydata', JSON.stringify(data));
}
});
}
function receive(){
window.addEventListener("storage",function(e){
if( e.key =='notifydata' && e.newValue){
var obj = JSON.parse(e.newValue);
if( obj.id != option.id && obj.notification){
window.parent.postMessage( obj, '*');
}
}
});
}
var option =parms( { } );
switch(option.type){
case 'sender': send();break;
case 'receiver': receive();break;
default: send();receive();
}
</script>