See the documentation for Notification in MDN and WHATWG , there seems to be no way to request permission revocation. However, you can emulate your own version of permissions with localStorage to support this missing functionality. Say you have a checkbox that toggles notifications.
<input type="checkbox" onChange="toggleNotificationPermissions(this);" />
You can save your remembered permissions under the notification-permissions key in local storage and update the permission status like this:
function toggleNotificationPermissions(input) { if (Notification.permissions === 'granted') { localStorage.setItem('notification-permissions', input.checked ? 'granted' : 'denied'); } else if (Notification.permissions === 'denied') { localStorage.setItem('notification-permissions', 'denied'); input.checked = false; } else if (Notification.permissions === 'default') { Notification.requestPermission(function(choice) { if (choice === 'granted') { localStorage.setItem('notification-permissions', input.checked ? 'granted' : 'denied'); } else { localStorage.setItem('notification-permissions', 'denied'); input.checked = false; } }); } }
You can get permissions like:
function getNotificationPermissions() { if (Notification.permissions === 'granted') { return localStorage.getItem('notification-permissions'); } else { return Notification.permissions; } }
If you want to display a notification, check your rights:
if (getNotificationPermissions() === 'granted') { new Notification(); }
source share