我一直在尝试向Meteor Web应用程序添加一个简单的HTML5桌面通知。这是代码,
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
var date = new Date();
var audio = new Audio();
audio.src = "../../../universal/bells.wav";
audio.load();
audio.play();
var notification = new Notification("Allow Notifications!", {
dir: "auto",
lang: "hi",
tag: "testTag"+date.getTime(),
icon: "../../../assets/notification.png",
});
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
var notification = new Notification("Granted Permission for Notifications");
}
});
}
但音频和图像都没有显示出来。 这是我收到的音频文件错误信息,
"未捕获(在承诺中)DOMException:无法加载,因为找不到支持的源。"
如果我注释掉代码的音频部分,则图像图标会抛出错误,
"拒绝加载图片' http://placekitten.com.s3.amazonaws.com/homepage-samples/96/139.jpg'因为它违反了以下内容安全策略指令:" img-src数据:' self' http:// .googleapis.com https:// .googleapis.com http:// .gstatic.com https:// .gstatic.com http:// .bootstrapcdn.com https:// .bootstrapcdn.com"。"
并且不显示图像。
有没有其他方法可以在Meteor App中实现桌面通知? 另外,有没有办法让通知出现在页面的中心?
答案 0 :(得分:0)
找到解决方案!所有媒体都必须在流星的公共文件夹中才能被访问!