Notification: permission static property
The permission
read-only property of the Notification
interface indicates the current permission granted by the user for the current origin to display web notifications.
Value
A string representing the current permission. The value can be:
-
granted
-
The user has explicitly granted permission for the current origin to display system notifications.
-
denied
-
The user has explicitly denied permission for the current origin to display system notifications.
-
default
-
The user decision is unknown; in this case the application will act as if permission was denied
.
Examples
The following snippet could be used if you wanted to first check whether notifications are supported, then check if permission has been granted for the current origin to send notifications, then request permission if required, before then sending a notification.
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
const notification = new Notification("Hi there!");
} else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
const notification = new Notification("Hi there!");
}
});
}
}
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
permission_static |
32 |
14 |
22 |
No |
23 |
7 |
No |
42 |
22 |
29 |
16.4 |
4.0 |
See also