Resetting denied HTML notifications
Asked Answered
B

2

9

I have a web app in which I am using HTML Notifications. It works fine if the user allows it for the first time and start using it, however if user blocks the notification the first time by clicking the block button and later on try to request permission again by some user gesture then the browser doesn't trigger (Allow/Block) popup.

Here is the second time I am triggering the permission.

if(Notification.permission == 'denied' || Notification.permission == 'default'){

        Notification.requestPermission(function (permission) {
    // If the user accepts, let's create a notification
            if (permission === "granted") {
                console.log("Regranted");
            }
        });
    }

It works fine for the default case but not for the denied case.

Blithering answered 30/6, 2015 at 8:56 Comment(7)
I'm not 100% but isn't this by design, else you could just spam the user requesting access constantly?Susannasusannah
Completely agree with @djsmiley2k. You are probably tring to make a adware kind of thing.Investigate
@Vibhor Dube :- My app has a button to enable notifications. (If the user for some reason blocked it earlier and now want to unblock using my app ~ I wanted to give him an option) to avoid any inconsistency. Thanks though !Blithering
Use this link to see the answer posted by me: enter link description hereStcyr
See the answer by clicking this link: enter link description hereStcyr
To see the answer go by this link: enter link description hereStcyr
I would advice you instead of immediately asking for Notification permissions, display a dialog or component to your user explaining what the notifications are for, then use a button to trigger Notification permission request. This way, your user would be in context when prompted to give permissionsIllmannered
I
14

The behavior you’re seeing is by design, as an earlier comment points out. If you read step 2, substep 2 at https://notifications.spec.whatwg.org/#dom-notification-requestpermission you’ll see the spec requires that the only time a user is asked whether showing notifications is acceptable is when the permission value is default. If the permission value is granted or blocked, that algorithm requires that the user is never asked again whether showing notifications is acceptable.

Users who do change their minds about notifications for a site they’ve blocked have the option to go into their browser settings to reset the permissions for that site themselves.

Itacolumite answered 7/8, 2015 at 2:19 Comment(1)
This is the correct answer. The only alternative to display the notification prompt multiple times (even if the user says "No" to the notifications) is to use two prompts: the first prompt is made with HTML+CSS and the second prompt is the real one. Check out this article about the double opt-inBreastwork
F
6

I would recommend having a button to turn notifications on, then checking the permission there, falling back if it's been previously denied.

ex:

  if (Notification.permission === "denied") {
    alert("Notifications blocked. Please enable them in your browser.");
  }
Fastigium answered 17/10, 2016 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.