31 lines
827 B
HTML
31 lines
827 B
HTML
|
|
<!doctype html>
|
||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8" />
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
|
<title>Document</title>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<button class="notify">send a notification</button>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
const Notifybtn = document.querySelector(".notify");
|
||
|
|
const sendNotification = () => {
|
||
|
|
if (!("Notification" in window)) {
|
||
|
|
throw new Error(
|
||
|
|
"Your browser does not support push notification",
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Notification.requestPermission().then((Permission) => {
|
||
|
|
const notificationOptions = {
|
||
|
|
body: "Welcome to Javascript Push Notification",
|
||
|
|
icon: "./image.png",
|
||
|
|
};
|
||
|
|
new Notification("Push Notification", notificationOptions);
|
||
|
|
});
|
||
|
|
};
|
||
|
|
Notifybtn.addEventListener("click", sendNotification);
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|