我正在努力倾听当需要"授权时发生的事件"显示对话框(参见Firefox Addon SDK Hotkeys and contect menu options dont work on Authentication Required Popup)。
但是我注意到XUL插件可以侦听DOMWillOpenModalDialog事件,当这个对话框打开时,该事件显然已被触发。似乎没有触发任何SDK面板事件。
有没有办法在插件SDK中监听此事件?
------ ------编辑
继续Noitidart的消化后,我尝试了其他一些事件并开火了。以下两种尝试均有效。
var events = require("sdk/system/events");
function listener(event) {console.log("An event popup was activated.");}
events.on("xul-window-visible", listener);
CWin.addEventListener("DOMWillOpenModalDialog", function() {CWin.setTimeout(NfyBox, 500);}, true);
function NfyBox() {
console.log("An event popup was activated.");
worker = tabs.activeTab.attach({
contentScriptFile: self.data.url("notifybox.js")
});
worker.port.emit("notify");
}
然而,就我所知,在contentScriptFile中,一个console.log文档产生: -
console.log: infstr: {"location":{"assign":"function assign() {\n [native cod
e]\n}","replace":"function replace() {\n [native code]\n}","reload":"function
reload() {\n [native code]\n}","toString":"function toString() {\n [nativ
e code]\n}","valueOf":"function valueOf() {\n [native code]\n}","href":"http:
//c1s4-1e-syd.hosting-services.net.au:2082/unprotected/redirect.html","origin":"
http://c1s4-1e-syd.hosting-services.net.au:2082","protocol":"http:","username":"
","password":"","host":"c1s4-1e-syd.hosting-services.net.au:2082","hostname":"c1
s4-1e-syd.hosting-services.net.au","port":"2082","pathname":"/unprotected/redire
ct.html","search":"","hash":""}}
但尝试获取getElementById或我尝试过的任何其他东西都是未定义的。我显然犯了一些简单的错误,但看不出它是什么。
答案 0 :(得分:0)
是听popup事件。在这种情况下popupshowing
:MDN : PopupEvents
这是一个阻止右上角的主菜单(三条纹菜单按钮)通过收听popuphiding
并阻止它来关闭的示例:
var PUI = Services.wm.getMostRecentWindow('navigator:browser').document.querySelector('#PanelUI-popup');
try {
PUI.removeEventListener('popuphiding', previt, false);
} catch (ignore) {}
var previt = function(e) {
PUI.style.opacity = 1;
e.stopPropagation();
e.preventDefault();
e.returnValue = false;
return false;
}
PUI.addEventListener('popuphiding', previt, false);