所以我有一个包含 CSS 的 HTML 文档,它定义了 DIV 页面的布局。我想打开一个新窗口并将 DIV 添加到此窗口,其中包含数组中的信息。 document.write 不起作用,因为它会删除现有页面并删除 CSS。我尝试过 newwindow.document.body.appendChild() 但没有任何显示。我错过了什么?
编辑:好吧,事实证明我的代码在 IE 中按预期工作,但在我测试它的 Chrome 中却不起作用。这似乎是一项安全措施,将其关闭。
var printWindow = window.open("widgets/eSearchPlus/this_is_a_test.html", "PrintLabels", "toolbar=yes, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));
var div = document.createElement('div');
div.className = "label";
div.innerHTML = "test";
printWindow.document.body.appendChild(div);
最佳答案
试试这个:
var printWindow = window.open("widgets/eSearchPlus/this_is_a_test.html", "PrintLabels", "toolbar=yes, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));
printWindow.document.body.innerHTML += '<div class="label">test</div>';
关于javascript - 使用 javascript 将 DIV 添加到弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30785210/