Created
November 12, 2013 12:32
-
-
Save ghooghe/7430085 to your computer and use it in GitHub Desktop.
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
| var canNotify = function() { | |
| if ("Notification" in window) { | |
| if (Notification.permission === 'granted') { | |
| return true; | |
| } else if (Notification.permission !== 'denied') { | |
| Notification.requestPermission(function (permission) { | |
| if(!('permission' in Notification)) { | |
| Notification.permission = permission; | |
| } | |
| // If the user is okay, let's create a notification | |
| if (permission === "granted") { | |
| return true; | |
| } | |
| }); | |
| } | |
| } | |
| return false; | |
| }; | |
| var notify = function(message) { | |
| if (canNotify()) { | |
| new Notification('Title', { | |
| tag: 'notification-id', | |
| body: message, | |
| icon: 'icon-url' | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment