【发布时间】:2025-11-26 07:10:02
【问题描述】:
我需要打印从后端系统发送的 html 转储。此打印是在从 UI 中单击按钮时触发的。我正在使用 window.print ,如下所示。这里的问题是,在加载打印预览时,它不应该阻止用户在父窗口中执行操作。但是,即使在新窗口上使用 window.print 时,父窗口也会被冻结和禁用。有没有办法在父窗口中启用用户访问?
以下代码用于打印:
function printElem(elem){
var newwindow = window.open('', 'PRINT');
newwindow.document.write('<html><head><title>' +
document.title + '</title>');
newwindow.document.write('</head><body >');
newwindow.document.write(elem);
newwindow.document.write('</body></html>');
newwindow.focus();
newwindow.print();
newwindow.close();
}
【问题讨论】:
-
你最好的办法是在
back-end上设置一个打印路由来处理打印哑数据,print()方法会打开一个模态窗口,这意味着它将阻止用户返回到像警报窗口一样的原始窗口
标签: javascript