1
根據MDN的Notification.permission規範,我們可以檢查當前Web用戶通知的用戶權限。如何收聽網絡通知權限更改
但是,有沒有什麼辦法來監聽這個權限更改?像這樣?
.on(Notification.permission, 'changed', function(){ }
根據MDN的Notification.permission規範,我們可以檢查當前Web用戶通知的用戶權限。如何收聽網絡通知權限更改
但是,有沒有什麼辦法來監聽這個權限更改?像這樣?
.on(Notification.permission, 'changed', function(){ }
我相信這個答案有點遲,但是...您可以使用它。
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);
};
});
}
});