在不同的窗口中追加相同的节点
Appending same node in different windows
我想添加一个在父窗口创建的对象到子窗口:
div = document.createElement( "div" );
document.body.appendChild( div );
// Here come div's atts;
render = window.open().document;
render.body.appendChild( div );
,但是新的DIV只被附加到子窗口。如果对最后一行进行注释,则div将追加到父窗口。这个问题能解决吗?
编辑,因为我误读了问题:
newelement = element.cloneNode(true); // true to clone children too
在新窗口中仍然没有可以附加的html或正文。至少在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>
您是否尝试创建该div的副本,然后将其附加到子div而不是原始div?
编辑:好的,那么是的,这将是cloneNode函数。
clone = div.cloneNode(true);
render = window.open().document;
render.body.appendChild(clone);
相关文章:
- 使用 Cheerio 追加节点的同级节点
- 追加到文档中尚未插入的新节点
- 如何检测 html 元素是否可以追加子节点
- 无法在 d3.js 中的节点上追加图像
- 追加子节点创建一个新节点
- 无法在节点上执行追加子项
- 如何在节点.js中追加到新行
- Uncaught HierarchyRequestError:追加节点失败
- 在不同的窗口中追加相同的节点
- 向节点追加文本
- D3向节点追加HTML
- 多个文件追加到节点js的响应对象中
- getElementsByClassName 返回 [] 而不是异步追加节点
- ajax请求成功后在jqtree中追加子节点的问题
- 在节点x追加子节点
- D3强制布局与图像作为节点,但错误的图像追加
- 是否有可能监视或以某种方式检测子dom节点何时追加到父节点
- HTML节点没有被追加
- 追加子节点的顺序是否重要
- 不能使用 jquery parseXML 追加 XML 节点,但可以追加字体