diff --git a/modules/ve/ve.js b/modules/ve/ve.js index d0fe74140a..2883510589 100644 --- a/modules/ve/ve.js +++ b/modules/ve/ve.js @@ -976,10 +976,34 @@ * @returns {HTMLDocument} Document constructed from the HTML string */ ve.createDocumentFromHTML = function ( html ) { - // According to the spec we should be using DOMParser.prototype.parseFromString or - // document.implementation.createHTMLDocument, but the former only works in Firefox - // and the latter doesn't work in IE9 and below. - // So we're using the good old iframe trick. + // Here's how this function should look: + // + // var newDocument = document.implementation.createHTMLDocument( '' ); + // newDocument.open(); + // newDocument.write( html ); + // newDocument.close(); + // return newDocument; + // + // (Or possibly something involving DOMParser.prototype.parseFromString, but that's Firefox-only + // for now.) + // + // Sadly, it's impossible: + // * On IE 9, calling open()/write() on such a document throws an "Unspecified error" (sic). + // * On Firefox 20, calling open()/write() doesn't actually do anything, including writing. + // This is reported as Firefox bug 867102. + // * On Opera 12, calling open()/write() behaves as if called on window.document, replacing the + // entire contents of the page with new HTML. This is reported as Opera bug DSK-384486. + // + // Funnily, in all of those browsers it's apparently perfectly legal and possible to access the + // newly created document's DOM itself, including modifying documentElement's innerHTML, which + // would achieve our goal. But that requires some nasty magic to strip off the tag + // itself, so we're not doing that. (We can't use .outerHTML, either, as the spec disallows + // assigning to it for the root element.) + // + // There is one more way - create an