admin管理员组文章数量:1425127
I have some html contents and image and print the page on button click. When i print it first time the print preview page is empty and second time it is fine. Please help on why it is not print the page first time
Image source is base-64 format. So, due to the large content, i not able to add code snippet, Please check with demo link.
<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
Anyone help me on this..
I have some html contents and image and print the page on button click. When i print it first time the print preview page is empty and second time it is fine. Please help on why it is not print the page first time
Image source is base-64 format. So, due to the large content, i not able to add code snippet, Please check with demo link.
<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
Anyone help me on this..
Share Improve this question edited Apr 19, 2017 at 10:17 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Apr 19, 2017 at 10:04 BharathiBharathi 1,3382 gold badges14 silver badges45 bronze badges3 Answers
Reset to default 6win.document.write(htmlContent);
win.document.close();
win.focus();
setTimeout(function(){win.print();win.close();}, 10);
Try it out,
change to
var win = window.open('', '', 'toolbar=0');
win.document.write(htmlContent);
win.document.onload = function () {
win.document.close();
win.focus();
win.print();
win.close();
};
this will work, on load will make sure that the page is loaded before executing next item.
var win = window.open('', '', 'toolbar=0');
win.document.write(htmlContent);
win.document.close();
win.focus();
setTimeout(function () {
win.print();},50);
window.close();
}
this will wait for 50 miliseconds before print execute .so your base64 image can bind on html...(TESTED)
本文标签: javascriptprinting is not working in chrome browser at first timeStack Overflow
版权声明:本文标题:javascript - printing is not working in chrome browser at first time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745442358a2658502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论