我正在使用浏览器的打印设备使用javascript。这是我做过的事情。
BindPrintPubReport: function () {
//Printed by Values.
var username = "Sanjeev";
//End.
var htmltags = '';
htmltags += '<h3 style="margin: 10px 0 20px 10px; border-left: 3px solid #4e8ff7; font-size: 23px; padding: 0 10px;">Report Header</h3>';
htmltags += '<div style="float:left;margin-right:88px;padding-left:10px;margin-top:-20px;">';
htmltags += '<div><span style="width:120px;display:inline-block;">Generated By : </span>' + username + '</div>'
//images or logo i want to add in report
htmltags += '<div style="float:left;margin-right:88px;padding-left:10px;margin-top:-20px;"><img src=http://localhost:1122/images/logo_02.png"/></div>';
//print document preparation
var docprint = window.open("", "_blank");
docprint.document.open();
docprint.document.write('<html mozNoMarginBoxes><head>');
docprint.document.write('<style>@page{ margin:45px 10px;}body{font-size:14px;}</style>');
docprint.document.write('</head><body >');
docprint.document.write(htmltags);
docprint.document.write('</body></html>');
//Start
docprint.focus();
docprint.print();
docprint.close();
//end.
}
首先我加载了,它在google crome和firefox中工作,但在google crome图像中没有加载。要在文档中加载图像,我替换代码,`
//Start
docprint.focus();
docprint.print();
docprint.close();
//end.
通过
//start
docprint.document.write("<script>$(window).load(function(){ docprint.print();docprint.close(); });</script>");
//end.
它会在google crome中加载图像,但打印在Firefox中无效。如上所述,打印行为不正常。我该如何为所有浏览器提供支持?
答案 0 :(得分:0)
我更改了代码:
//Start
docprint.focus();
docprint.print();
docprint.close();
//end.
到
$(docprint).ready(function () {
setTimeout(
function () {
docprint.focus();
docprint.print();
docprint.close();
}, (1000));
});
最终适用于Firefox和Google Chrome浏览器。