Created
December 15, 2016 05:12
-
-
Save gabber12/440ced8421407192426fab7e4c7442b6 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
Notification.requestPermission().then(function(result) { | |
console.log(result); | |
}); | |
var notify = function(message) { | |
// Let's check if the browser supports notifications | |
if (!("Notification" in window)) { | |
alert("This browser does not support system notifications"); | |
} | |
// Let's check whether notification permissions have already been granted | |
else if (Notification.permission === "granted") { | |
// If it's okay let's create a notification | |
console.log("dsads"); | |
var notification = new Notification('dsadsa',{ | |
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', | |
body: "Hey there! You've been notified!", | |
}); | |
} | |
// 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('dsa'); | |
} | |
}); | |
} | |
// Finally, if the user has denied notifications and you | |
// want to be respectful there is no need to bother them any more. | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment