HTML通知自动被拒绝

时间:2017-01-24 14:35:13

标签: javascript html5-notifications

我正在尝试使用以下方法设置HTML桌面通知:

// Let's check if the browser supports notifications
        if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
        }
        // Let's check if the user is okay to get some notification
        else if (window.Notification.permission === "granted") {
            // If it's okay let's create a notification
            var options = {
                body: "This is the body of the notification",
                dir : "ltr"
            };
            var notification = new window.Notification("Hi there",options);
        }
        // Otherwise, we need to ask the user for permission
        // Note, Chrome does not implement the permission static property
        // So we have to check for NOT 'denied' instead of 'default'
        else if (window.Notification.permission !== 'denied') {
            console.log('Requesting Notification permission ' + window.Notification.permission);
            window.Notification.requestPermission(function (permission) {
                console.log('Got resolve of request permission ' + permission);
                // Whatever the user answers, we make sure we store the information
                if (!('permission' in window.Notification)) {
                    window.Notification.permission = permission;
                }

                // If the user is okay, let's create a notification
                if (permission === "granted") {
                    var options = {
                        body: "This is the body of the notification",
                        dir : "ltr"
                    };
                    var notification = new window.Notification("Hi there",options);
                }
            });
        }

但是我没有看到弹出窗口允许通知;而是自动拒绝requestPermission。

0 个答案:

没有答案