我试图将XUL School Hello World扩展程序修改为Firefox,以便打开侧边栏而不是弹出窗口。不幸的是,我似乎无法通过"指定的无效侧边栏广播公司"错误。
有效的侧边栏广播员会是什么样子?
browserOverlay.js:
/**
* XULSchoolChrome namespace.
*/
if ("undefined" == typeof(XULSchoolChrome)) {
var XULSchoolChrome = {};
};
/**
* Controls the browser overlay for the Hello World extension.
*/
XULSchoolChrome.BrowserOverlay = {
/**
* Says 'Hello' to the user.
*/
sayHello : function(aEvent) {
let stringBundle = document.getElementById("xulschoolhello-string-bundle");
let message = stringBundle.getString("xulschoolhello.greeting.label");
// window.alert(message);
SidebarUI.toggle("xulschoolhello-sidebar");
}
};
browserOverlay.xul:
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet type="text/css"
href="chrome://xulschoolhello/skin/browserOverlay.css" ?>
<!DOCTYPE overlay SYSTEM
"chrome://xulschoolhello/locale/browserOverlay.dtd">
<overlay id="xulschoolhello-browser-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
src="chrome://xulschoolhello/content/browserOverlay.js" />
<stringbundleset id="stringbundleset">
<stringbundle id="xulschoolhello-string-bundle"
src="chrome://xulschoolhello/locale/browserOverlay.properties" />
</stringbundleset>
<menubar id="main-menubar">
<menu id="xulschoolhello-hello-menu" label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloMenu.accesskey;" insertafter="helpMenu">
<menupopup>
<menuitem id="xulschoolhello-hello-menu-item"
label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloItem.accesskey;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
</menupopup>
</menu>
</menubar>
<vbox id="appmenuSecondaryPane">
<menu id="xulschoolhello-hello-menu-2" label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloMenu.accesskey;"
insertafter="appmenu_addons">
<menupopup>
<menuitem id="xulschoolhello-hello-menu-item-2"
label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloItem.accesskey;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
</menupopup>
</menu>
</vbox>
<menupopup id="viewSidebarMenu">
<menuitem id="xulschoolhello-sidebar"
label="&xulschoolhello.sidebar.title;"
type="checkbox" autoCheck="false" group="sidebar"
sidebarurl="chrome://xulschoolhello/content/sidebar.html"
sidebartitle="&xulschoolhello.sidebar.title;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
</menupopup>
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="xulschoolhello-hello-world-button"
class="toolbarbutton-1 chromeclass-toolbar-additional"
label="&xulschoolhello.hello.label;"
tooltiptext="&xulschoolhello.hello.tooltip;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
<!-- More buttons here. -->
</toolbarpalette>
<broadcasterset id="MainBroadcasterSet">
<broadcaster id="hello-sidebar"
sidebarurl="chrome://xulschoolhello/content/sidebar.html"
sidebartitle="Hello world!"
group="sdiebar" />
</broadcasterset>
</overlay>
显然,在XUL School Hello World示例中还有更多文件。
答案 0 :(得分:0)
通过查看SidebarUtil.toggle() source code可以找到此错误消息的原因。 SidebarUI
找不到身份broadcaster
的{{1}}。
您需要更改
xulschoolhello-sidebar
到
SidebarUI.toggle("xulschoolhello-sidebar");
xul文件中也有拼写错误。我相信SidebarUI.toggle("hello-sidebar");
应为group="sdiebar"
注意:如果您正在学习XUL来创建firefox扩展,我强烈建议您查看Addon SDK。基于XUL的API很快就会被弃用。