I have a iframe page and would like to extract the DOM node from the child frame and put it on the parent page. This works in Firefox (3.5), but not in Internet Explorer (7).
I broke the code into the simplest option.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Fragment</title> </head> <body> <iframe src="blank.html"></iframe> <script type="text/javascript"> window.onload = function () { var fragment = document.createDocumentFragment(); var div = frames[0].document.createElement("div"); fragment.appendChild(div); }; </script> </body> </html>
I get the error " Invalid argument " in the line " fragment.appendChild(div); ". The error seems to be due to the fact that I am creating a document fragment from an iframe document and a div element from the parent document. This code works if both use the same document.
I want to save any events that can be attached to DOM nodes, so I don't want to use innerHTML.
Does anyone know a fix for this?
source share