我正在尝试为 Firefox Electrothesis 编写一个插件。当我打开 e10s 窗口并右键单击页面元素时,document.popupNode 对于 e10s 窗口不可用。
var WindowListener = {
setupBrowserUI: function(window) {
//
},
tearDownBrowserUI: function(window) {
},
// nsIWindowMediatorListener functions
onOpenWindow: function(xulWindow) {
var domWindow = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
// Wait for it to finish loading
domWindow.addEventListener("load", function listener() {
domWindow.removeEventListener("load", listener, false);
// If this is a browser window then setup its UI
if (domWindow.document.documentElement.getAttribute("windowtype")=="navigator:browser") {
domWindow.document.getElementById('contentAreaContextMenu').addEventListener("popupshowing", function(event){
let document=event.currentTarget.ownerDocument;
let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
prompts.alert(null, "Test", document.popupNode);
}, false);
}
}, false);
},
onCloseWindow: function(xulWindow) {
},
onWindowTitleChange: function(xulWindow, newTitle) {
}
};
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
// Wait for any new browser windows to open
wm.addListener(WindowListener);
您可以在Scratchpad中使用测试代码。运行测试代码后,打开一个新的普通 Firefox 窗口,然后在网页内右键单击。 document.popupNode 出现提示警报。
但是,如果打开新的 e10s Firefox 窗口并右键单击,它不会显示任何内容。
如何在 e10s windows 中获取 document.popupNode?p>
最佳答案
没有 document.popupNode
因为 XUL 文档没有在节点上弹出任何内容。相反,它从子进程收到一条消息,告诉它在特定的屏幕坐标处显示菜单。
而是使用 gContextMenu.target
,它是从 gContextMenuContentData.event.target
填充的。
gContextMenu.target
适用于所有浏览器窗口,而 gContextMenuContentData.event.target
仅适用于 e10s 窗口。
当然,gContextMenu
仅在弹出窗口即将显示或正在显示时才有效。
关于javascript - 如何在 Firefox Electrothesis 窗口中获取 document.popupNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24954664/