Firefox附加组件:触发页面中节点上的内容区域上下文菜单

时间:2014-01-04 20:25:02

标签: firefox firefox-addon firefox-addon-sdk

如何在页面文档中的特定节点上触发浏览器的菜单弹出#contentAreaContextMenu?

在我的附加组件中,我已经解决了这个问题

let windowUtil = require("sdk/window/utils");

let win = windowUtil.getMostRecentBrowserWindow();
let popup = win.document.querySelector("#contentAreaContextMenu");
popup.openPopup(null, "", 194, 264, true, false);

这会打开我想要的上下文菜单弹出窗口,但它是未过滤的/没有上下文 我需要触发页面文档中的图像。

openPopup方法中的第一个参数被称为“锚点”,听起来就像我所追求的那样,但我没有让它成功。

popup.openPopup(imageNodeInPageDocument ..)

提前致谢

2 个答案:

答案 0 :(得分:0)

弹出窗口的处理程序将查看menupopup.triggerNode property以查看它打开的元素。您当前打开弹出窗口的方式将不会设置此属性。 Starting with Firefox 4您可以在调用triggerEvent时指定可选的openPopup()参数:

var event = new CustomEvent("myCustomEvent");

// Make sure event.target is set correctly
imageNodeInPageDocument.dispatchEvent(event);

popup.openPopup(null, "", 194, 264, true, false, event);

这应该确保上下文菜单知道它正在打开哪个元素。

答案 1 :(得分:-1)

怎么样..

    mynode.setAttribute("context", "contentAreaContextMenu");
相关问题