Skip to content Skip to sidebar Skip to footer

Notification Popup Doesn't Appear In Chrome

I am trying to do a gmail similar type desktop notification . I am facing the difficulty to change the notification permission in chrome. The permission always shows denied in cons

Solution 1:

There seem to be a problem with your script.

It's part of the standard that when the permission is set to denied you can NEVER show the popup which asks "Do you want to allow... to send desktop notifications ?". This popup is used only in the case the permission is set to default, which in fact means that the user doesn't care and you should ask him if he wants them or not.

This is the conditionnal I use :

Notification['permission'] !== 'granted' && Notification['permission'] !== 'denied'

Because the default value isn't supported by all browsers. Plus the permission attribute was not implemented prior to chrome 32, that's why you should access it using the square brackets.

In fact you could also remove the denied part in my conditionnal, because it won't do anything if the permission is denied. You can refer to this MDN documentation to get more information on compatibility and things like that.


Solution 2:

Issue of not opening dialog box is http. Chrome desktop notification work only on https protocol.

I have faced this issue and I have spend many time to solved that. Finally I got solution using https.

Here I shared code so you can run on https and it will working fine.

enter code here
       // request permission on page load
    document.addEventListener('DOMContentLoaded', function () {
      if (!Notification) {
        alert('Desktop notifications not available in your browser. Try Chromium.'); 
        return;
      }

      if (Notification.permission !== "granted")
        Notification.requestPermission();
    });

    function notifyMe() {
      if (Notification.permission !== "granted")
        Notification.requestPermission();
      else {
        var notification = new Notification('Notification title', {
          icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
          body: "Hey there! You've been notified!",
        });

        notification.onclick = function () {
          window.open("http://stackoverflow.com/a/13328397/1269037");      
        };

      }

    }

    notifyMe();

    Call notifyMe(); to show notification

Post a Comment for "Notification Popup Doesn't Appear In Chrome"