【发布时间】:2014-02-13 01:22:30
【问题描述】:
我想在 javascript 中创建一个 iframe 元素,它有一个文档和一个 <head> 和 <body>。
dom中不能存在iframe。这部分很关键。
以下尝试无效:
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)
我也尝试在 dom 中创建它,然后尝试克隆它,但是克隆的 iframe 不再包含文档。
【问题讨论】:
标签: javascript jquery html iframe