I want to create an iframe element which has a document and a <head>
and <body>
in javascript.
The iframe cannot exist in the dom. This part is critical.
The following attempts do not work:
var frame = $('<iframe />'); // [<iframe></iframe>]
var doc = document.implementation.createHTMLDocument() // #document
// TypeError: Cannot read property 'ownerDocument' of null
frame.append(doc);
// HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Nodes of type '#document' may not be inserted inside nodes of type 'IFRAME'.
frame.get(0).appendChild(doc)
I also tried creating it in the dom, and then trying to clone it, but the cloned iframe no longer contains a document.