为什么chrome的notification功能不生效?

经测试,在chrome上会问是否开启通知,但是来了消息没通知。 在火狐,2345有通知效果。
2345: 5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.4.2.17629
chrome 5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36

代码如下:

Notification.requestPermission(function (permission) {

// If the user accepts, let's create a notification
    if (!("Notification" in window)) {

        alert("此浏览器不支持消息提醒功能");

    }
});
function notifyFunc(tag,title,body,icon) {


// check whether notification permissions have alredy been granted

    if (Notification.permission == "granted") {

// If it's okay let's create a notification

        var notification = new Notification(title, {
            body: body,
            icon: icon,
            tag: tag,
            renotify: true
        });
        notification.onclick = function() {
            //可直接打开通知notification相关联的tab窗口
            window.focus();
            notification.close();
        }

    }

// Otherwise, ask the user for permission

    else if (Notification.permission != 'denied') {

        Notification.requestPermission(function (permission) {

// If the user accepts, let's create a notification

            if (permission == "granted") {

                new Notification("Request granted!");

            }

        });

    }
}

有大佬知道这是为啥吗

阅读 8.2k
1 个回答

在线测试还是本地测试,如果在线测试不出来可能是协议的原因(谷歌安全限制),用https就可以了,本地的话是浏览器版本问题,之前遇到过,换版本就可以了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题