How do I make a div contentEditable in an xul file (Firefox Extension)?
This is my first ever question on stackoverflow, but I have made quite a few trips here to solve other problems, but I can't find an answer for this one: How do I make a div contentEditable in an xul file for a Firefox Extension?
-The following is the part of my .xul file which contains the div I want contentEditable:
<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>
When I do this, I receive the following error in the sidebar of my extension:
XML Parsing Error: not well-formed<br/>
Location: chrome开发者_JAVA百科://emptysidebar/content/emptysidebar.xul<br/>
Line Number 41, Column 29:<br/>
`<html:div contentEditable value="Tryitout"style="width:150px;height:200px"/>
-------------------------------^`
I have found some examples in which the div is done this way, where instead of just saying contentEditable you say 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>
When I do that, I do not receive any errors, but nothing is displayed but a blank 150x200 pixel box. Is there something I am missing that makes a contentEditable div possible in an xul file for a Firefox Extension?
What you are using here is XHTML, not HTML. It has to follow the rules of XML and XML doesn't support attribute minimization, see http://www.w3.org/TR/xhtml1/#h-4.5. You should use the full form instead:
<html:div contentEditable="contentEditable" ...
That said, I wouldn't be surprised if contentEditable
isn't working correctly in XUL - HTML embedded in XUL is often not doing what's expected. It might be better to use an <iframe>
tag, load an HTML file into it (e.g. about:blank
) and set document.designMode = "on"
on this document.
精彩评论