开启按钮单击我正在尝试打印#idThermal内容。第一次它没有显示在打印预览上,但第二次它完全正常
var divContents = $("#idThermal").html();
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title></title>');
printWindow.document.write('<link href="/Content/ThermalPrint.css" rel="stylesheet" />');
printWindow.document.write('</head><body onload=' + printWindow + '.print(); ' +
printWindow + '.close();>');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
答案 0 :(得分:0)
也许你的意思是:
var divContents = $("#idThermal").html();
var printWindow = window.open('', '', 'height=400,width=800');
var html = '<html><head><title></title>'+
'<link href="/Content/ThermalPrint.css" rel="stylesheet" />'+
'</head><body onload="window.focus(); window.print()">'+
divContents+
'</body></html>';
printWindow.document.write(html);
printWindow.document.close();