Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Firefox windows中获取document.popupNode_Javascript_Firefox_Firefox Addon_E10s - Fatal编程技术网

Javascript 如何在Firefox windows中获取document.popupNode

Javascript 如何在Firefox windows中获取document.popupNode,javascript,firefox,firefox-addon,e10s,Javascript,Firefox,Firefox Addon,E10s,我正在尝试为Firefox编写一个插件。打开e10s窗口并右键单击页面元素时,document.popupNode不适用于e10s窗口 var WindowListener = { setupBrowserUI: function(window) { // }, tearDownBrowserUI: function(window) { }, // nsIWindowMediatorListener functions onOpen

我正在尝试为Firefox编写一个插件。打开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文档在节点上没有弹出任何内容。相反,它从子进程收到一条消息,告诉它在某些屏幕坐标处显示菜单

相反,请使用从
gcontextmenucontdata.event.target
填充的
gContextMenu.target

gContextMenu.target
可用于所有浏览器窗口,而
gContextMenuContentData.event.target
仅在e10s窗口中可用

当然,
gContextMenu
仅在弹出窗口即将显示或正在显示时有效