javascript - 使用 javascript 将 DIV 添加到弹出窗口

标签 javascript html

所以我有一个包含 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/

相关文章:

javascript - 是否可以扩展正则表达式元字符的范围?

javascript - 如何将元素保持在 float 元素之下?

javascript - 使用 NW.js (Node Webkit) 执行 Windows 文件/事件

javascript - 如果父级的高度 div 高于 X,则显示此 div

python - 为什么我的 JSON 脚本没有从 FLASK 获取 JSONIFY 返回?

javascript - 从字符串中逐个删除字符

javascript - 需要帮助修复我的 isotope.js [jquery 和 html 代码]

迭代两个数组进行命中检测时出现 Javascript 错误

javascript - Firebase 代码 400 "message": "CONFIGURATION_NOT_FOUND"

html - 垂直居中和水平顶部对齐位置固定元素