How to disable Webkit notifications?

Is there a way to give the user the ability to disable webkitNotifications? If I call a requestPermission()second time, it does not request the user.

+5
source share
3 answers

I just ask permission once, then I let the user configure whether he wants to receive notifications from the configuration panel.

localStorage.

if (notificationsEnabled) {
    var notification = new window.Notification("Hello");
}

$(function () {
    notificationsEnabled = JSON.parse(localStorage.getItem('notificationsEnabled') || false);
    $('#notificationsEnabled').prop('checked', notificationsEnabled);

    if (!window.Notification) {
        $('#notificationsEnabled').prop('disabled', true);
    }
});

<label>
    <input id="notificationsEnabled" name="notificationsEnabled" type="checkbox">
    Enable notifications
</label>

onchange

$('#notificationsEnabled').on('change', function() {
    notificationsEnabled = !notificationsEnabled;
    localStorage.setItem('notificationsEnabled', notificationsEnabled);
    if (notificationsEnabled && window.Notification.permission === 'default') {
        window.Notification.requestPermission();
    }
});
0

Chrome :

  • ( )
  • Click " Settings "
  • Click " Show advanced settings ... "
  • In the " Privacy " section, click " Content Settings "
  • In the " Notifications " section, click " Manage exceptions. "

You can reset to receive notifications.

-1
source

All Articles