2013-03-28 126 views
0

這是我的代碼的精簡版。 我試圖在firefox的右鍵上下文菜單中顯示一個菜單項。爲什麼gContextMenu爲空?

Here gContextMenu顯示爲空,並且它鎖定了Firefox的上下文菜單。 我在調試2天后發現了這個問題。

<?xml version="1.0"?> 

<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> 
<?xml-stylesheet href="chrome://foobar/skin/foobar.css" type="text/css"?> 

<!DOCTYPE window SYSTEM "chrome://foobar/locale/foobar.dtd"> 

<overlay id="foobar-browser-overlay" 
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 



    <stringbundleset id="stringbundleset"> 
    <stringbundle id="foobar-string-bundle" src="chrome://foobar/locale/foobar.properties"/> 
    </stringbundleset> 

    <popup id="contentAreaContextMenu" onpopupshowing="alert(gContextMenu)"> 
     <menuseparator /> 
     <menuitem id="foobar-show-meaning" label="&foobar.showmeaning.label;" /> 
    </popup> 
</overlay> 

注:
我指的是http://kb.mozillazine.org/Adding_items_to_menus一個菜單項,選擇文本時添加到Firefox的上下文菜單,纔會顯示。但調試後,發現根本原因是gContextMenu爲空。

  1. 我的Firefox版本是19.0.2

  2. 我不想使用新的插件,SDK,因爲它剝奪了,我打算以後添加更精細的控制。 (更細的控制一樣 - 控制窗口的大小,它的x,y座標)

  3. 我是新手,當涉及到XUL發展的現在..

  4. 我引用:https://developer.mozilla.org/en-US/docs/XUL/School_tutorial
    https://developer.mozilla.org/en-US/docs/XUL/PopupGuide/Extensions
    https://developer.mozilla.org/en-US/docs/XUL/PopupGuide/ContextMenus#Hiding_and_Showing_Menu_Items_based_on_Context

回答

1

彈出元素已經很久以前棄用,更改覆蓋相應

<menupopup id="contentAreaContextMenu" 
... 
</menupopup> 

也不要使用內聯事件處理程序,它可能會覆蓋原始。 Add an event listener programmatically

+0

這不行!它仍然顯示爲空警報! X( 這是我的新代碼.. \t '\t \t \t \t \t <菜單項ID =「foobar的-展示 - 意思是「label =」&foobar.showmeaning.label;「/> \t' – user1422163

+0

我更新了答案。 – paa