create a javascript document Object

document, javascript, object

Solution

Webkit was the first to include/expose the following method for that task:

document.implementation.createHTMLDocument(title);

Firefox, from version 4, also implements this method while for previous versions it is possible to create an HTML document using the following:

var doc = document.implementation.createDocument('', '',
  document.implementation.createDocumentType('html', '', ''));

which should be roughly equivalent to a document having `<!DOCTYPE html>` (HTML5).

Replace the empty strings of 'createDocumentType' with the needed publicId/systemId.

It will be still necessary to create/append html, head and body elements to the resulting document to have a working DOM.

Problem

Is there any way to create or recreate a javascript document Object by calling a function. Something like ``` <script type="javascript/text"> var document = createDocument("some html"); </script> ``` I want to do this so I can solve the issue in this question client side xslt with javascript in firefox

Original source

Related problems