在附加不同的窗口同一个节点 [英] Appending same node in different windows
本文介绍了在附加不同的窗口同一个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要追加一个对象,那是在一个父窗口创建一个子窗口:
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附加仅对子窗口。如果我评论的最后一行 - 股利追加到父窗口。可以在解决?
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或身体。在镀铬至少没有。
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>
这篇关于在附加不同的窗口同一个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文