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);
};
});
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…