Last active
May 7, 2021 12:53
-
-
Save liron-navon/378c8f8699882e0397c719208a5bb6dc to your computer and use it in GitHub Desktop.
a simple example for a notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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