Chrome上的原生通知无效

时间:2014-01-07 00:15:32

标签: javascript google-chrome notifications

我一直在尝试使用this script from MDN的修改版本,在Chrome上使用原生通知。

function notify(title, body, icon){
    if(!("Notification" in window)){
        alert("This browser does not support desktop notification");
    }else if(Notification.permission === "granted"){
        var notification = new Notification(
            title,
                {
                    body: body,
                    tag: new Date().getTime(),
                    icon: icon
                }
            );
    }else if(Notification.permission !== "denied"){
        Notification.requestPermission(function(permission){
            if(!("permission" in Notification)) {
                Notification.permission = permission;
            }
            if (permission === "granted") {
                var notification = new Notification(
                    title,
                        {
                            body: body,
                            tag: new Date().getTime(),
                            icon: icon
                        }
                );
            }
    });
  }
}

notify("Test title", "Test message", "http://cdn1.iconfinder.com/data/icons/windows-8-metro-style/26/message.png");

http://jsfiddle.net/AKak9/4/

在Chrome上(它在Safari和Firefox中运行良好),脚本根本不做任何事情,但MDN的原始脚本运行正常。

0 个答案:

没有答案