簡體   English   中英

Firefox-顯示來自擴展程序/附件的Web通知

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM