Created
October 26, 2019 20:04
-
-
Save strukturart/c22822bb20eae206b5a2f5c7b4df9f76 to your computer and use it in GitHub Desktop.
KaiOS 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
function notify(param_title,param_text,param_silent) { | |
var options = { | |
body: param_text, | |
silent: param_silent | |
} | |
// Let's check if the browser supports notifications | |
if (!("Notification" in window)) { | |
alert("This browser does not support desktop notification"); | |
} | |
// Let's check whether notification permissions have already been granted | |
else if (Notification.permission === "granted") { | |
// If it's okay let's create a notification | |
var notification = new Notification(param_title,options); | |
} | |
// 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") { | |
var notification = new Notification(param_title,options); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment