contentEditable on nodes in a XML/compound document?

杀马特。学长 韩版系。学妹 提交于 2020-01-22 02:24:46

问题


I have an XML document that I'm displaying in a web browser, with a stylesheet attached:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/css" href="abc.css"?>
<myxml xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <para>I wish i was editable</para>
    <xhtml:script type="text/javascript" src="abc.js"/>
</myxml>

With the xhtml namespace declaration, and xhtml:script tag, I can execute javascript.

What I'd like to do is to make arbitrary non-XHTML elements in this document content editable. (Actually, they'll be in another namespace)

Even if I explicitly add @contentEditable="true" (ie without resorting to Javascript), the content is not actually editable (in Firefox 3.0.4).

Is it possible to edit it in any of the current browsers? (I had no problems with <div contentEditable="true">Edit me</div> in an XHTML 1.0 Transitional doc)

I can't even edit an xhtml:div in this document (in Firefox); if I could do that, that may offer a way forward.


回答1:


In Firefox 3, @content-editable="true" only makes the relevant element editable if the content type is text/html (which also happens if a local filename ends with .html)

It doesn't work for content types app/xhtml+xml or text/xml (local filenames ending with .xhtml or .xml)

I've logged an enhancement for this: https://bugzilla.mozilla.org/show_bug.cgi?id=486931




回答2:


contentEditable works (tested in Firefox and Chrome) on elements which are foreign to html/xhtml if I use this doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html4/loose.dtd">

and a .html file extension (instead of .xml).

I don't have to include any html elements at all (eg head, body, div, p).

css isn't applied though (if my xml is in a namespace, which i guess makes sense, given the doctype!).

Not an elegant solution.




回答3:


Firefox is one of the few browsers that strictly enforces the XHTML spec. So, to make an element editable, you must specify the contenteditable attribute as true. Note that the whole attribute name is lower case. In your example the first "E" in editable was capitalized.

Another quirk that should be mentioned is that IE(6,7,8) act exactly the opposite. To make an element editable in IE, you MUST add contentEditable="true" exactly. For what ever reason, contenteditable="true" (as well as any other variation in capitalization) does not work.



来源:https://stackoverflow.com/questions/713919/contenteditable-on-nodes-in-a-xml-compound-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!