I'd like to save the html string of the DOM, and later restore it to be exactly the same. The code looks something like this:
var stringified = document.documentElement.innerHTML // later, after serializing and deserializing document.documentElement.innerHTML = stringified
This works when everything is perfect, but when the DOM is not w3c-comliant, there's a problem. The first line works fine,
stringified matches the DOM exactly. But when I restore from the (non-w3c-compliant)
stringified, the browser does some magic and the resulting DOM is not the same as it was originally.
For example, if my original DOM looks like
then the final DOM will look like
div elements are not allowed to be inside
p elements. Is there some way I can get the browser to use the same html parsing that it does on page load and accept broken html as-is?
Why is the html broken in the first place? The DOM is not controlled by me.
Here's a jsfiddle to show the behavior http://jsfiddle.net/b2x7rnfm/5/. Open your console.