我有一个 JS 函数,当有人单击按钮时,它会打印我的 html 页面(页面的下半部分)的名为divDisplay的特定 div 的内容。当用户与页面交互时,这个 div 的内容是动态接收的( ajax )。打印在 FF、OPERA、IE 中完美运行,但在要打印的弹出窗口中的 chrome 和 safari 中,数据被打乱,没有颜色并且不在正确的位置(好像没有 css 格式)。
function jsPrintDiv(m) {
glblPopupWindow = window.open("", "PrintWindow", "width=1024,height=768,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
glblPopupWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="stylesheet" type="text/css" href="styles.css"></head><body><div name="divDisplay" id="divDisplay">' + document.getElementById(m).innerHTML + '</div></body></html>');
glblPopupWindow.document.close();
glblPopupWindow.document.getElementById("divDisplay").style.top = "0px";
glblPopupWindow.focus();
glblPopupWindow.print();
glblPopupWindow.close();
}
styles.css与进行打印的原始 html 页面所具有的 css 文件相同。doctype也是如此。
divDisplay的CSS :
#divDisplay {
position: absolute;
left: 0.2%;
top: 305px;
width: 99.6%;
bottom: 0.5%;
/* height: expression(document.body.offsetHeight - 314 + "px"); */
overflow: auto;
background-color: #AACCFF;
font-family: palatino linotype;
font: palatino linotype;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
有什么想法我可能做错了吗?提前致谢!
编辑:
要打印的弹出窗口中的正确数据(firefox):http: //img208.imageshack.us/img208/8195/ffprint.jpg
要打印的弹出窗口中的加扰数据(chrome):http: //img152.imageshack.us/img152/6108/chprint.jpg
EDIT2: 如果我注释掉
glblPopupWindow.print();
行,chrome正确显示它。不知道这是否有帮助。