我一直在尝试使用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");
在Chrome上(它在Safari和Firefox中运行良好),脚本根本不做任何事情,但MDN的原始脚本运行正常。