Skip to content

Instantly share code, notes, and snippets.

@strukturart
Created October 26, 2019 20:04
Show Gist options
  • Save strukturart/c22822bb20eae206b5a2f5c7b4df9f76 to your computer and use it in GitHub Desktop.
Save strukturart/c22822bb20eae206b5a2f5c7b4df9f76 to your computer and use it in GitHub Desktop.
KaiOS notification
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