2007年4月14日星期六

appendChild() invalid for frame?

See http://lists.evolt.org/archive/Week-of-Mon-20030616/143280.html
In trying to use the DOM to perform some acrobatics for a CMS, using
cloneNode() and appendNode() to try to copy some default XHTML into a 
IFRAME:

<html> <body onload="initFrame()">
<div id="foo" style="display: none">this is some <em>foo</em> for you</div>
<iframe id="theFrame" width="310" height="100"></iframe>
<script>
  function initFrame() {
      var newNodes = document.getElementById('foo').cloneNode(true);
      newNodes.style.display = 'block';
      var idoc = 
document.getElementById('theFrame').contentWindow.document;
      idoc.body.appendChild(newNodes);
  }
</script>
</body></html>

This works fine in Mozilla. IE6 says "Invalid Argument" at the 
appendChild()
line. Have tried many permutations of replaceChild(), insertBefore(), etc.
with the same result. It does work if the node I am appending to is in the
same document (not in a separate frame)...
I got the same problem. Until now the only key I found is to change "innerHTML" of the iframe. Some one said:
You´re accessing the iframe incorrectly. Try frames[´theFrame´].document instead. See http://www.xs4all.nl/~ppk/js/index.html?iframe.html for more information.
By using "frames[´theFrame´].document" I got the same result, It's also invalid.

没有评论: