此代码适用于firefox&即但不是铬。善意的建议。
function printdata(){
var printHtml = "";
printHtml = printHtml + "<html>";
printHtml = printHtml + "<head>";
printHtml = printHtml + "<title>www.MyDomain.com</title>";
printHtml = printHtml + "<style>body{background:#fff;} .allow_border td{border:1px solid #000; padding:2px 5px;} div{text-align:left;}</style>";
printHtml = printHtml + "</head>";
printHtml = printHtml + "<body>";
printHtml = printHtml + "<div>";
printHtml = printHtml + document.getElementById("divPrintArea").innerHTML;
printHtml = printHtml + "</div>";
printHtml = printHtml + "</body>";
win = window.open('XXXXXXX', 'XXXXXXX', 'width=1,height=1,left=250,top=250');
win.document.write(printHtml);
win.document.close();
win.focus();
win.print();
答案 0 :(得分:0)
在使用chrome和opera调用print方法之前,可能需要添加超时。
这是一个可能的解决方案: http://danielbergsten.wordpress.com/2011/01/11/javascript-window-print-does-not-work-in-operachrome-browser/