Is the conversion from HTML to DOM and back to HTM

2019-08-27 22:20发布

问题:

I'm working on an rich-text editor that will be using ContentEditable. It's imperative that a document that is loaded into the browser (from the web server) is not altered in any way by the conversion to DOM, and then back to HTML alone (assuming the user has not made any changes).

It's alright if the HTML document is modified the first time it's created and saved by a browser, but subsequently should not occur again, which simply requires that all browsers will produce the same DOM based on equivalent HTML, and the same HTML output based on equivalent DOMs. Is this something that I can rely upon?

回答1:

It's easy to demonstrate that the markup doesn't round-trip when the serialisation is performed with innerHTML or outerHTML.

Take markup that starts as <div id='mydiv'></div>. In IE9 that becomes <div id="mydiv"></div>. In IE8, it becomes <DIV id=mydiv></DIV>