Can't appendChild to a node created from another frame

こ雲淡風輕ζ 提交于 2019-11-29 07:47:33

Your problem is that you are not adopting the nodes into the fragment that are created in the current document. Use either the following:

fragment.appendChild(fragment.ownerDocument.createElement("div"));

or

fragment.appendChild(fragment.ownerDocument.adoptNode(document.createElement("div"));

I'm just hazarding a guess here, but you could try creating the div using

var div = frames[0].document.createElement("div") 

instead of

var div = document.createElement("div") 

Using the main document's createElement() method may be why IE is having a problem.

I think I found the answer here: http://www.alistapart.com/articles/crossbrowserscripting/

Importing documents from two different ownerDocument properties ... requires the use of the DOM Level 2 method importNode(), since in these cases the DOM will not allow a simple document.appendChild().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!