Created
January 25, 2016 22:27
-
-
Save ddeveloperr/8ff401e0afafb49404f9 to your computer and use it in GitHub Desktop.
This part of code is responsible for desktop 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
| // This part of code is responsible for desktop notification :) | |
| function notifyMe(title, options) { | |
| // Check if the browser supports notifications | |
| if (!("Notification" in window)) { | |
| console.log("This browser does not support desktop notification"); | |
| } | |
| // Check whether notification permissions have alredy been granted | |
| else if (Notification.permission === "granted") { | |
| // If it's okay let's create a notification | |
| var notification = new Notification(title, options); | |
| } | |
| // Otherwise, we need to ask the user for permission | |
| else if (Notification.permission !== 'denied') { | |
| Notification.requestPermission(function (permission) { | |
| // If the user accepts, let's create a notification | |
| if (permission === "granted") { | |
| var notification = new Notification(title, options); | |
| } | |
| }); | |
| } | |
| } | |
| var title = "ddeveloperr's Notification"; | |
| var options = { | |
| body: "ddeveloperrs Notification Body", | |
| icon: "http://i.imgur.com/7RdS6AH.png" | |
| } | |
| notifyMe(title, options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment