本文介绍了在不同的窗口中附加相同的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将在父窗口中创建的对象附加到子窗口:
I want to append an object, that was created in a parent window to a child window:
div = document.createElement( "div" );
document.body.appendChild( div );
// Here come div's atts;
render = window.open().document;
render.body.appendChild( div );
但新的 DIV 仅附加到子窗口.如果我评论最后一行 - div 将附加到父窗口.能解决吗?
but the new DIV is appended only to the child window. If I comment the last line - the div is appended to the parent window. Can that be solved?
推荐答案
编辑,因为我误读了问题:
Editing since I misread the question:
newelement = element.cloneNode(true); // true to clone children too
在新窗口中仍然没有可以附加的 html 或 body.至少在 chrome 中不是.
Still there is no html or body in the new window that it can be appended to. At least not in chrome.
试试这个:
<html>
<body>
<script>
div = document.createElement( "div" );
// add some text to know if it's really there
div.innerText = 'text of the div';
document.body.appendChild( div );
// Here come div's atts;
render = window.open().document;
// create the body of the new document
render.write('<html><body></body></html>');
// now you can append the div
render.body.appendChild( div );
alert(render.body.innerHTML);
</script>
</body>
</html>
这篇关于在不同的窗口中附加相同的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!