2011-05-19 69 views
0

Firefox擁有一個原生通知框系統: https://developer.mozilla.org/en/Code_snippets/Alerts_and_Notifications#Using_notification_boxFirefox擴展,使通知框出現在所有選項卡

我想,當它是應該的,因爲它出現在所有打開的標籤的方式來使用這個系統出現。我只在當前打開的標籤中警告你。

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow); 
var nb = mainWindow.gBrowser.getNotificationBox(); 
//... 
outdatedNotification = nb.appendNotification("Your information outdated", 
           'outdate-warn', 
           'chrome://checksistem/skin/checksistem.png', 
           priority, buttons); 

回答

3

每個選項卡都有自己的通知框。您只需循環瀏覽所有瀏覽器並將通知添加到每個瀏覽器。你應該知道的一件事是gBrowser.getNotificationBox可以利用瀏覽器元素:

http://mxr.mozilla.org/mozilla-central/source/browser/base/content/tabbrowser.xml#337

如果你不通過瀏覽器,代碼返回活動選項卡的通知框。

試試這個:

 
    var browsers = mainWindow.gBrowser.browsers; 
    for (var i=0; i<browsers.length; i++) { 
    var nb = mainWindow.gBrowser.getNotificationBox(browsers[i]); 
    outdatedNotification = nb.appendNotification("Your information outdated", 
            'outdate-warn', 
            'chrome://checksistem/skin/checksistem.png', 
            priority, buttons); 
    }