0

这段代码在 Firefox 和 ie 中工作,但在 chrome 中没有。请建议。

函数打印数据(){

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();
4

1 回答 1

0

在 chrome 和 opera 中调用 print 方法之前,您可能必须添加一个超时。

这是一个可能的解决方案: http: //danielbergsten.wordpress.com/2011/01/11/javascript-window-print-does-not-work-in-operachrome-browser/

于 2012-04-07T12:06:39.933 回答