Skip to content

Instantly share code, notes, and snippets.

@gabber12
Created December 15, 2016 05:12
Show Gist options
  • Save gabber12/440ced8421407192426fab7e4c7442b6 to your computer and use it in GitHub Desktop.
Save gabber12/440ced8421407192426fab7e4c7442b6 to your computer and use it in GitHub Desktop.
<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