如何在 Firefox 页面加载时通知正确的选项卡?
我使用 Firefox 附加 SDK 构建了以下代码,成功将通知添加到 页面加载时,当前活动选项卡上的NotificationBox
。
如何将其更改为使用 getNotificationBox()
方法,以便选择属于正在加载的 Document
的选项卡上的 NotificationBox
?
const observer = require( 'observer-service' );
var {Cc, Ci, Cr, Cu} = require( 'chrome' );
observer.add( 'document-element-inserted', function( document ) {
var window = document.defaultView;
var mainWindow = window.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIWebNavigation )
.QueryInterface( Ci.nsIDocShellTreeItem )
.rootTreeItem
.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIDOMWindow );
var notificationBox = mainWindow.gBrowser.getNotificationBox();
notificationBox.appendNotification(
'This is my message',
'myNotifyId',
'chrome://global/skin/icons/information-16.png',
notificationBox.PRIORITY_INFO_LOW
);
});
I have built the following code with the Firefox add-on SDK that successfully adds a notification to the NotificationBox
on the current active tab, at page-load time.
How can I change it to use the parameterised version of the getNotificationBox()
method, in order to select the NotificationBox
on the tab that belongs to the Document
being loaded?
const observer = require( 'observer-service' );
var {Cc, Ci, Cr, Cu} = require( 'chrome' );
observer.add( 'document-element-inserted', function( document ) {
var window = document.defaultView;
var mainWindow = window.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIWebNavigation )
.QueryInterface( Ci.nsIDocShellTreeItem )
.rootTreeItem
.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIDOMWindow );
var notificationBox = mainWindow.gBrowser.getNotificationBox();
notificationBox.appendNotification(
'This is my message',
'myNotifyId',
'chrome://global/skin/icons/information-16.png',
notificationBox.PRIORITY_INFO_LOW
);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
如果
document
可能是一个框架,则需要使用document.defaultView.top.document
代替。Try:
If
document
might be a frame, you would need to usedocument.defaultView.top.document
instead.