javascript - 如何在 Firefox Electrothesis 窗口中获取 document.popupNode

标签 javascript firefox firefox-addon e10s

我正在尝试为 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?

最佳答案

没有 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/

相关文章:

javascript - 有没有更好的方法来编写这个 mutuple 或 conditional ?

javascript - 在 .live ('keyup' 中使用 .val 时,jquery .change 未在 ie 中触发,function()

javascript - Firefox 附加组件开发 |重写browser.xul

javascript - 使用 javascript 加载 XUL 资源

javascript - Firefox 附加组件 SDK 1.16 的 Web 控制台中的 console.log

Javascript:获取当前元素的同级元素 [CKEditor 需要]

javascript - 如何从使用 jquery 添加的项目中删除属性

javascript - 使用 knockoutjs 绑定(bind)在 firefox 中将多行文本显示为单行

forms - CSS 伪选择器::before 和::after 将不会在 FF 44 和 IE11 中显示

html - 记住密码在 ff 中有效,但在 ie 和 chrome 中无效