[英]Firefox - displaying web notifications from extension/addon
我正在构建Firefox插件(带有addon-SDK),并且希望向用户显示桌面通知。 有Notification对象,但似乎在附加代码(背景页面)中不起作用。 没有错误等,但没有显示权限对话框,因此无法显示任何通知。 我当然尝试添加权限/桌面通知,但没有效果。
编辑:粘贴我尝试过的示例代码(该代码位于socket.io事件的回调函数内。事件已正确接收,但未显示通知或请求权限。
Notification.requestPermission( function(status) {
console.log(status); // notifications will only be displayed if "granted"
var n = new Notification("title", {body: "notification body"}); // this also shows the notification
});
我还发现了警报服务这一功能。 但是,警报消失得很快(对我来说太快了)-编辑:这就是它的工作方式-因此无需猜测代码示例,因为我看不到任何使它们持续时间更长的选项。
有什么方法可以在Firefox上显示类似Chrome的通知吗? (chrome.notifications.create)还是至少使用插件中的Web通知对象?
如果您使用的是附加SDK,则会查看错误的文档。 这是通知文档 。
您可以这样创建一个通知:
var notifications = require("sdk/notifications");
notifications.notify({
title: "Jabberwocky",
text: "'Twas brillig, and the slithy toves",
data: "did gyre and gimble in the wabe",
onClick: function (data) {
console.log(data);
}
});
您查看的所有文档都应该是developer.mozilla.org/en-US/Add-ons/SDK的子集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.