-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.html
60 lines (60 loc) · 1.75 KB
/
notifications.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
<head>
<link rel="stylesheet" href="main.css" />
</head>
<html>
<body>
<div class="container">
<h1>Notifications</h1>
<p>Type something in the box below and click notify!</p>
<input
id="input"
type="text"
placeholder="What text do you want to notify?"
/>
<button onclick="notifyMe()" id="button">Notify me!</button>
</div>
</body>
</html>
<script>
function notifyMe() {
if (!window.Notification) {
alert("Sorry! Your browser does not support notifications.");
} else {
// check if permission is already granted
if (Notification.permission === "granted") {
// show notification here
var notify = new Notification("Hi there!", {
body: document.getElementById("input").value,
icon: "favicon.ico",
});
} else {
// request permission from user
Notification.requestPermission()
.then(function (p) {
if (p === "granted") {
// show notification here
var notify = new Notification("Hi there!", {
body: document.getElementById("input").value,
icon: "favicon.ico",
});
} else {
alert("You blocked notifications! >:(");
}
})
.catch(function (err) {
alert("Hmm, there was an error! Error:" + err);
});
}
}
}
</script>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<script>
$("h1, h2, h3")
.css("text-align", "center")
.append(
'<hr style="height: 1px; background: linear-gradient(to right, transparent , var(--color), transparent); padding: 0px; border: none;">'
);
</script>