Is there a way I can give a user the option of disabling webkitNotifications? If I call requestPermission()
a second time, it does not prompt the user.
Asked
Active
Viewed 757 times
5

rds
- 26,253
- 19
- 107
- 134

user1502301
- 565
- 1
- 4
- 16
3 Answers
0
I just ask for the permissions once, then I let the user configure whether he wants to receive notifications from a configuration panel.
You can store this option in a database on the server or client-side with localStorage
.
Display notification
if (notificationsEnabled) {
var notification = new window.Notification("Hello");
}
Restore setting on load
$(function () {
notificationsEnabled = JSON.parse(localStorage.getItem('notificationsEnabled') || false);
$('#notificationsEnabled').prop('checked', notificationsEnabled);
if (!window.Notification) {
$('#notificationsEnabled').prop('disabled', true);
}
});
Settings
<label>
<input id="notificationsEnabled" name="notificationsEnabled" type="checkbox">
Enable notifications
</label>
Handle onchange events on the checkbox
$('#notificationsEnabled').on('change', function() {
notificationsEnabled = !notificationsEnabled;
localStorage.setItem('notificationsEnabled', notificationsEnabled);
if (notificationsEnabled && window.Notification.permission === 'default') {
window.Notification.requestPermission();
}
});

Fred
- 12,086
- 7
- 60
- 83
-1
If you're in Chrome try this:
- Bring up the menu (it's hidden to the right of the address bar)
- Click "Settings"
- Click "Show advanced settings..."
- Under "Privacy" click "Content Settings"
- Under "Notifications" click "Manage exceptions"
You can reset the notifications there.

Coomie
- 4,832
- 3
- 32
- 44