我用
创建了一个上下文菜单项覆盖<menupopup id="contentAreaContextMenu" onpopupshowing="XULSchoolChrome.BrowserOverlay.test(event)">
<menuitem id="thumbnail-show-etes"
label="My Label"
class="menuitem-iconic"
image="chrome://xulschoolhello/skin/favicon.png"
oncommand="XULSchoolChrome.BrowserOverlay.injectScript('tap_browser.js');"/>
</menupopup>
功能测试(事件)是
test: function(aEvent) {
var localName = aEvent.target.triggerNode.localName;
this.clickOnImage = (localName == "img") ? true : false;
console.log(localName, ' click on image ', this.clickOnImage);
}
我不明白为什么调用此功能会显示每个菜单项?
解决方案
我发现解决方案是改变&#34; onpopupshowing&#34; to&#34; onpopupshown&#34;
<menupopup id="contentAreaContextMenu" onpopupshown="XULSchoolChrome.BrowserOverlay.test(event)">
<menuitem id="thumbnail-show-etes"
label="My Label"
class="menuitem-iconic"
image="chrome://xulschoolhello/skin/favicon.png"
oncommand="XULSchoolChrome.BrowserOverlay.injectScript('tap_browser.js');"/>
</menupopup>
答案 0 :(得分:1)
我找到了解决方案。这是从“onpopupshowing”改为“onpopupshown”
<menupopup id="contentAreaContextMenu" onpopupshown="XULSchoolChrome.BrowserOverlay.test(event)">
<menuitem id="thumbnail-show-etes"
label="My Label"
class="menuitem-iconic"
image="chrome://xulschoolhello/skin/favicon.png"
oncommand="XULSchoolChrome.BrowserOverlay.injectScript('tap_browser.js');"/>
</menupopup>
答案 1 :(得分:0)
将您的功能更改为:
test: function(aEvent) {
var img;
if(gContextMenu.onImage) {
img = aEvent.originalTarget
}
else if(gContextMenu.hasBGImage && !gContextMenu.isTextSelected) {
var imgURL = gContextMenu.bgImageURL;
}
console.log(img,' click on image ', img);
}
我只是在试验