我有一些 html 内容和图像,并在单击按钮时打印页面。当我第一次打印它时,打印预览页面是空的,第二次就可以了。请帮忙解释为什么第一次打印不出来
图像源是 base-64 格式。因此,由于内容太多,我无法添加代码片段,请查看演示链接。
<input type="button" id="printImage" onclick=printImage() value="print" />
function printImage() {
var htmlContent = "The html code in stack-overflow exceeded. So please check with demo link for html content";
var win = window.open();
win.document.write(htmlContent);
win.document.close();
win.focus();
win.print();
win.close();
}
任何人都可以帮助我......
最佳答案
win.document.write(htmlContent);
win.document.close();
win.focus();
setTimeout(function(){win.print();win.close();}, 10);
关于javascript - 第一次在 chrome 浏览器中打印不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43492512/