Skip to content

Instantly share code, notes, and snippets.

@liron-navon
Last active May 7, 2021 12:53
Show Gist options
  • Select an option

  • Save liron-navon/378c8f8699882e0397c719208a5bb6dc to your computer and use it in GitHub Desktop.

Select an option

Save liron-navon/378c8f8699882e0397c719208a5bb6dc to your computer and use it in GitHub Desktop.
a simple example for a notification
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
function notify() {
new Notification("Hello world!");
}
// Let's check whether notification permissions have already been granted
if (Notification.permission === "granted") {
notify();
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function(permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
notify();
} else {
// the user doesn't want a notification 🤷‍♀️
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment