-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (58 loc) · 2.58 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OSX Notification Center</title>
<!-- jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- demo scripts -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<script type="text/javascript">
$(function() {
function notifyMe( title, options ) {
// Let's check if the browser supports notifications
if ( ! ( "Notification" in window ) ) {
$('.support, .no-permission, .notify-click').hide();
return;
}
$( '.no-support' ).hide();
// Let's check whether notification permissions have already been granted.
if (Notification.permission === "granted") {
$( '.no-permission' ).hide();
var notification = new Notification( title, options );
}
// Otherwise, we need to ask the user for permission.
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function ( permission ) {
if (permission === "granted") {
$( '.no-permission' ).hide();
var notification = new Notification( title, options );
}
});
}
}
notifyMe( 'Hi, there! 👋', { body: 'Welcome to our website' });
$('.button').on('click', function() {
notifyMe( 'Hi, there 👋', { body: 'You\'ve just clicked the button.' });
});
});
</script>
<!-- nav script -->
</head>
<body>
<!-- demo content -->
<div class="demo-wrapper">
<div class="notify-support">
<p class="alert support">Awesome, your browser supports Notification Center feature.</p>
<p class="alert no-support">Unfortunately, your browser does not support Notification Center feature. If it does, you should see somthing as shown in this screenshot below.</p>
<p class="alert no-permission">You have denied to show the Notification. You can enable it from the <strong>Preference</strong> options.</p>
</div>
<div class="notify-click">
<small>Alternatively, you can also click on this button to get notified.</small>
<button type="button">Notify Me Again!</button>
</div>
</div>
<!-- Github ribbon -->
<div><a href="https://github.com/hongkiat/osx-notification-center"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a></div>
</body>
</html>