0

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.

dezman
  • 18,087
  • 10
  • 53
  • 91

1 Answers1

0

Can you use this? it will add content to your iframe

frame.contents().find('html').html("content"); //content: content of your document
joy
  • 130
  • 3