According to the Notification.permission spec from MDN, we can check the current user permission for web notification.
However, is there any way to listen for this permission change? Something like this?
.on(Notification.permission, 'changed', function(){ }
Generally speaking, you should ask users for permissions only when absolutely necessary and only after ensuring that users understand how granting this access will benefit them.
I believe it's a little late for an answer, but... You can use this.
var Notification = window.Notification || window.mozNotification || window.webkitNotification;
var was_questioned = false;
if (Notification.permission == 'default') {
was_questioned = true;
}
Notification.requestPermission(function (permission) {
if (was_questioned) {
console.log("User was asked. New permission is: " + permission);
}
if ('permissions' in navigator) {
navigator.permissions.query({name:'notifications'}).then(function(notificationPerm) {
notificationPerm.onchange = function() {
console.log("User decided to change his seettings. New permission: " + notificationPerm.state);
};
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With