Note: This feature is available in Web Workers.
Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
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.
Syntax
var permission = Notification.permission;
Value
A DOMString
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 wasdenied
.
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() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}
// Let's check whether notification permissions have alredy been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied' || Notification.permission === "default") {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
Specifications
Specification | Status | Comment |
Notifications APIThe definition of 'permission' in that specification. | Living Standard | Living standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
permission
|
Chrome
Full support Yes |
Edge
Full support 14 |
Firefox
Full support Yes |
IE
No support No |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
No support No |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
See also
Notification.permission by Mozilla Contributors is licensed under CC-BY-SA 2.5.