我在一个无需重启的附加组件中应用这样的绑定:
var css = '.findbar-container { -moz-binding:url("' + self.path.chrome + 'findbar.xml#matchword") }';
var cssEnc = encodeURIComponent(css);
var newURIParam = {
aURL: 'data:text/css,' + cssEnc,
aOriginCharset: null,
aBaseURI: null
}
cssUri = Services.io.newURI(newURIParam.aURL, newURIParam.aOriginCharset, newURIParam.aBaseURI);
myServices.sss.loadAndRegisterSheet(cssUri, myServices.sss.USER_SHEET);
findbar.xml
内容是:
<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="matchword">
<content>
<children/>
<xul:toolbarbutton anonid="matchwordbtn" accesskey="w" class="tabbable" label="Whole Word Only" tooltiptext="Match only whole words" oncommand="console.log('hi')" type="checkbox"/>
</content>
</binding>
</bindings>
这只是将一个按钮添加到FindBar
标有“仅全字”的标签上。但现在要删除它,我只是取消注册样式表myServices.sss.unregisterSheet(cssUri, myServices.sss.USER_SHEET);
,但这并没有解除绑定。
ask.mozilla.org 上的回答告诉我这是预期的行为,但没有提供解决方案。
我在想也许我应该动态添加绑定而不是通过 CSS,我没有对此进行测试,但它不符合 XBL 更新的 3 个原因:
- 绑定元素匹配指定不同绑定的样式规则
- 元素从绑定的文档中移除
- 元素被销毁(例如,通过关闭文档)
答案告诉我这是预期但时髦的行为。