如何在xul文件中创建div contentEditable(Firefox扩展)?

时间:2011-06-24 20:53:09

标签: html xul

这是我关于stackoverflow的第一个问题,但是我已经在这里做了很多次去解决其他问题,但我找不到这个问题的答案:如何在xul文件中创建div contentEditable Firefox扩展?

- 以下是我的.xul文件的一部分,其中包含我想要contentEditable的div:

<page id="sbEmptySidebar" title="&emptysidebar.title;"
     xmlns:html="http://www.w3.org/1999/xhtml">
<vbox flex="1">
<label id="atest" value="&emptysidebar.title;" />
</vbox>
<html:div contentEditable value="Tryitout" style="width:150px;height:200px"/>
<html:input type="button" value="Bold" onclick="document.execCommand('bold',false,null);"/>
</page>

当我这样做时,我在扩展程序的侧边栏中收到以下错误:

XML Parsing Error: not well-formed<br/>
Location: chrome://emptysidebar/content/emptysidebar.xul<br/>
Line Number 41, Column 29:<br/>
`<html:div contentEditable value="Tryitout"style="width:150px;height:200px"/>
-------------------------------^`

我找到了一些div以这种方式完成的例子,而不只是说contentEditable你说contentEditable =“true”:

<page id="sbEmptySidebar" title="&emptysidebar.title;"
xmlns:html="http://www.w3.org/1999/xhtml">
<vbox flex="1">
<label id="atest" value="&emptysidebar.title;" />
</vbox>
<html:div contentEditable="true" value="Tryitout" style="width:150px;height:200px"/>
<html:input type="button" value="Bold" onclick="document.execCommand('bold',false,null);"/>
</page>

当我这样做时,我没有收到任何错误,但没有显示任何内容,只有一个空白的150x200像素框。是否有一些我缺少的内容使得在Firefox扩展的xul文件中可以使用contentEditable div?

1 个答案:

答案 0 :(得分:1)

您在这里使用的是XHTML,而不是HTML。它必须遵循XML规则,XML不支持属性最小化,请参阅http://www.w3.org/TR/xhtml1/#h-4.5。您应该使用完整的表格:

<html:div contentEditable="contentEditable" ...

也就是说,如果contentEditable在XUL中无法正常工作,我不会感到惊讶 - 在XUL中嵌入的HTML通常不会达到预期的效果。最好使用<iframe>代码,在其中加载HTML文件(例如about:blank)并在此文档上设置document.designMode = "on"

相关问题