5

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.

rds
  • 26,253
  • 19
  • 107
  • 134
user1502301
  • 565
  • 1
  • 4
  • 16

3 Answers3

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

You could try presetting users preferences for notifications in code:

http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/SendingNotifications.html

Chad Adams
  • 1,319
  • 1
  • 9
  • 14
-1

If you're in Chrome try this:

  1. Bring up the menu (it's hidden to the right of the address bar)
  2. Click "Settings"
  3. Click "Show advanced settings..."
  4. Under "Privacy" click "Content Settings"
  5. Under "Notifications" click "Manage exceptions"

You can reset the notifications there.

Coomie
  • 4,832
  • 3
  • 32
  • 44