【发布时间】:2017-05-17 17:14:09
【问题描述】:
我正在打印从后端检索到的 html。
printHtml(htmlTemplate) {
var printWindow = window.open('', '_blank');
printWindow.document.write(htmlTemplate);
setTimeout(function () {
printWindow.document.close(); // necessary for IE >= 10
printWindow.focus(); // necessary for IE >= 10*/
printWindow.print();
printWindow.close();
}, 1000);
}
这在所有浏览器中都可以正常工作,唯一我不知道的是如何停止弹出窗口阻止程序。 无法使用 printWindow.location,因为 html 存在于变量中。
【问题讨论】:
-
你是如何打开这个弹出窗口的?在用户操作或其他事情之后? “如果打开选项卡/弹出窗口的命令来自受信任的事件,浏览器只会打开一个选项卡/弹出窗口,而不会发出弹出窗口阻止程序警告。”请参阅this question了解更多详细信息。
-
@abhishekkannojia 我通过单击按钮触发此操作并打开浏览器打印窗口。
标签: javascript jquery typescript browser cross-browser