答案 0 :(得分:0)
您可以发送此类通知,但首先您必须询问用户是否允许通知。
Notification.requestPermission(function() {
if (Notification.permission === 'granted') {
// user approved.
// use of new Notification(...) syntax will now be successful
new Notification('Success', { body: 'Success!' });
} else if (Notification.permission === 'denied') {
// user denied.
} else { // Notification.permission === 'default'
// user didn’t make a decision.
// You can’t send notifications until they grant permission.
}
});