-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdesktopapp.html
71 lines (61 loc) · 1.61 KB
/
desktopapp.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>desktop Notification - Sql</title>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
</head>
<body>
<a href='#' id="dnperm">Reuqest Permission</a><br />
<a href='#' id="dntrigger">Trigger</a><br />
<a href="#" id="insertRow">Insert Row</a><br />
<script type="text/javascript">
var dnperm = document.getElementById('dnperm');
var dntrigger = document.getElementById('dntrigger');
var sqlData = null;
dnperm.addEventListener('click',function(e){
e.preventDefault();
if(!window.Notification){
alert('Not supported');
}else{
Notification.requestPermission().then(function(p){
if(p=='denied'){
alert('You denied to show notification');
}else if(p=='granted'){
alert('You allowed to show notification');
}
});
}
});
dntrigger.addEventListener('click', function(e){
e.preventDefault();
if(Notification.permission!=='default'){
$.get('/html5api/webapiget.php',function(data){
sqlData = JSON.parse(data);
for(var i=0;i<sqlData.length;i++){
var notify;
notify= new Notification('New message - '+sqlData[i].id,{
'body': sqlData[i].value,
'icon': 'images.jpeg',
'tag': sqlData[i].id
});
notify.onclick = function(){
alert(this.tag);
}
}
});
}else{
alert('Please allow the notification first');
}
});
$('#insertRow').click(function(e){
e.preventDefault();
$.get('/html5api/webapipost.php',function(data){
alert(data);
});
});
</script>
</body>
</html>