2011-05-19 74 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); 
    }