2016-02-05 65 views

回答

0

我相信這個答案有點遲,但是...您可以使用它。

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); 
     }; 
    }); 
    } 
});