Parsing HTML From Chrome

Chrome  25.0.1364.5 dev. At least some well formed HTML can be parsed by lying about the MIMEtype thus:

var doc = parser.parseFromString(html, "text/xml");

Using "text/html" always returns null, even if the the html is correct and simple, eg

new DOMParser().parseFromString("<html><head></head><body></body></html>", "text/html");

The form:

 var doc = document.implementation.createHTMLDocument("");
 doc.body.innerHTML = html;

seems to work fine for one case I tried. I guess it should work well in general.

Document Tags and Contributors

Contributors to this page: MykMelez, Nickolay, Shaver, Hsivonen, JohnJBarton1
Last updated by: JohnJBarton1,