Requesting permission to send notifications
suggest changeNotification.requestPermission asks whether the page may show notifications. Call it from a user gesture. Current browsers require a secure context. The callback form is obsolete. The method returns a promise that fulfills with "granted", "denied", or "default". A denial is that string, not a rejection. Notification.permission is read-only.
Notification.requestPermission().then(function(permission) {
if (permission === "granted") {
// new Notification(...) can succeed
} else if (permission === "denied") {
// the user denied permission
} else {
// "default": the user dismissed the prompt
}
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents