javascript - 第一次在 chrome 浏览器中打印不工作

标签 javascript jquery html printing

我有一些 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();
}

sample demo link

任何人都可以帮助我......

最佳答案

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/

相关文章:

javascript - 嵌套 reducer

javascript - 路由端点内部/外部的Node.js,Express和对象实例化

html - 通过将鼠标悬停在单独的元素上来触发 CSS 动画

html - 为页脚 Bootstrap 着色以使其响应

html - CSS中的 "div>p"和 "div p"有什么区别

javascript - 如何在 Bootstrap 中制作粘性侧边栏?

javascript - 获取个人帖子id

jquery去除闪烁

javascript - 使用 Bootstrap 3 和 AngularJS 的多选下拉列表?

javascript - 使用数据属性选择面板