[英]How create splitmenu in Firefox addon
如何在Firefox插件中创建splitmenu? 我做这个:
var itemx = window.document.createElement('splitmenu');
itemx.setAttribute("style", '-moz-binding: url("chrome://browser/content/urlbarBindings.xml#splitmenu")'); window.document.getElementById("contentAreaContextMenu").appendChild(itemx);
看起来不太好。 我找不到文档。
您的代码的效果如下:
匿名缺少元素?
好的,事实证明,需要mor绑定,因此可以链接到“ browser.css”或从中复制绑定:
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
splitmenu {
-moz-binding: url("chrome://browser/content/urlbarBindings.xml#splitmenu");
}
.splitmenu-menuitem {
-moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem");
list-style-image: inherit;
-moz-image-region: inherit;
}
.splitmenu-menuitem[iconic="true"] {
-moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem-iconic");
}
.splitmenu-menu > .menu-text,
:-moz-any(.splitmenu-menu, .splitmenu-menuitem) > .menu-accel-container,
#appmenu-editmenu > .menu-text,
#appmenu-editmenu > .menu-accel-container {
display: none;
}
似乎在Firefox 28上,已引用browser.css
,但未在较新版本中...。
使用js代码进行测试将很麻烦,所以我使用xul窗口进行了测试:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/global.css"?>
<!--<?xml-stylesheet href="chrome://browser/content/browser.css" type="text/css"?>-->
<?xml-stylesheet href="chrome://mdsy_test/content/splitmenu/binding.css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
persist="screenX screenY width height">
<menubar>
<menu id="file-menu" label="File" accesskey="F">
<menupopup id="menu_FilePopup">
<menuitem id="menu_newNavigatorTab" label="New Tab" command="cmd_newNavigatorTab" key="key_newNavigatorTab" accesskey="T"/>
<menuseparator/>
<splitmenu label="cool" oncommand="alert('SPLIT')">
<menupopup>
<menuitem label="menu item!" oncommand="alert('ITEM')"/>
</menupopup>
</splitmenu>
</menupopup>
</menu>
</menubar>
</window>
我在Firefox 16、28和29上进行了测试
尝试这个:
var itemx = window.document.createElement('splitmenu');
itemx.setAttribute("style", '-moz-binding: url("chrome://browser/content/urlbarBindings.xml#splitmenu")');
itemx.setAttribute("label", "cool");
var pop = window.document.createElement('menupopup');
itemx.appendChild(pop);
var m = window.document.createElement('menuitem');
m.setAttribute("label", "menu item!");
pop.appendChild(m);
window.document.getElementById("contentAreaContextMenu").appendChild(itemx);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.