-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathnotifyme.html
125 lines (105 loc) · 3.19 KB
/
notifyme.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<html>
<!--
Desktop Notification API Demo.
http://0xfe.blogspot.com/2010/04/desktop-notifications-with-webkit.html
-->
<head>
<title>0xfe - Desktop Notification Demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
body {
padding: 20px;
background: white;
font-family: Caslon, Garamond, Arial, Helvetica, sans-serif;
font-size: 18px;
color: green;
margin: 0px;
height: 80%;
}
a {
color: #green;
text-decoration: none;
border-bottom: dotted 2px;
}
a.button {
color: #green;
background: #bfb;
text-decoration: none;
padding: 5px;
margin: 2px;
border: 5px solid #aea;
}
div#error {
width: 60%;
padding: 10px;
color: red;
background: #faa;
border: 15px solid #d99;
}
</style>
<script>
function Notifier() {}
// Returns "true" if this browser supports notifications.
Notifier.prototype.HasSupport = function() {
if (window.webkitNotifications) {
return true;
} else {
return false;
}
}
// Request permission for this page to send notifications. If allowed,
// calls function "cb" with true.
Notifier.prototype.RequestPermission = function(cb) {
window.webkitNotifications.requestPermission(function() {
if (cb) { cb(window.webkitNotifications.checkPermission() == 0); }
});
}
// Popup a notification with icon, title, and body. Returns false if
// permission was not granted.
Notifier.prototype.Notify = function(icon, title, body) {
if (window.webkitNotifications.checkPermission() == 0) {
var popup = window.webkitNotifications.createNotification(
icon, title, body);
popup.show();
return true;
}
return false;
}
$(function() {
var notifier = new Notifier();
if (!notifier.HasSupport()) {
$("#error").show();
return;
}
$("#request-permission").click(function() {
$("#error").hide();
notifier.RequestPermission();
});
$("#notify-me").click(function() {
if (!notifier.Notify("", "Notifier", "Hello Desktop!")) {
$("#error").text('Permission denied. Click "Request Permission" to give this domain access to send notifications to your desktop.');
$("#error").show();
} else {
$("#error").hide();
}
});
});
</script>
</head>
<body>
<center>
<h2>Desktop Notification Demo</h2>
<div id="error" style="display:none;">
This browser does not support desktop notifications. Try
<a href="http://www.google.com/chrome">Chrome</a> instead.
</div>
<p>
<a href="#" class="button" id="request-permission">Request Permission</a>
<a href="#" class="button" id="notify-me">Notify Me</a>
</p>
<p>
For details on how this works, visit <a href="http://0xfe.blogspot.com/2010/04/desktop-notifications-with-webkit.html">0xfe.blogspot.com</a> or <a href="http://github.com/0xfe/experiments/raw/master/www/notifyme.html">view the source</a>.
</p>
</center>
</body>
</html>