嗨,大家好,我正在使用这个jQuery函数来打印div内容。 第一次显示/打印空白页面。但第二次它的工作。 它显示div内容在console.log()
但不打印这些内容。打印div内容时出错
我想找出问题,但坚持下去。请帮忙
在此先感谢。
jQuery.fn.LBCprint = function()
{
var jStyleDiv = '';
var strFrameName = ("printer-" + (new Date()).getTime());
var jFrame = $("<iframe name='"+strFrameName+"'>");
jFrame.css("width", "1px").css("height", "1px").css("position", "absolute").css("left", "-9999px").appendTo($("body:first"));
// Get a FRAMES reference to the new frame.
var objFrame = window.frames[strFrameName];
// Get a reference to the DOM in the new frame.
var objDoc = objFrame.document;
jStyleDiv = $("<div>").append(
$("style").clone()
);
objDoc.open();
objDoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
objDoc.write("<html>");
objDoc.write("<head>");
objDoc.write("<title>");
objDoc.write(document.title);
objDoc.write("</title>");
objDoc.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.abc.com/n/css/main_style_print.css\" />");
objDoc.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.abc.com/n/css/dashboard.css\" />");
objDoc.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.abc.com/assets/css/pagination.css\" />");
objDoc.write("</head>");
objDoc.write("<body>");
objDoc.write(jStyleDiv.html());
objDoc.write(this.html());
objDoc.write("</body>");
objDoc.write("</html>");
objDoc.close();
// Print the document.
objFrame.focus();
objFrame.print();
jStyleDiv = '';
setTimeout(function(){
jFrame.remove();
}, (10000));
}
**不要**使用'document.write',但奇怪的是覆盖文件。 – adeneo 2014-08-27 15:05:24
@adeneo什么是替代? plz – Haseeb 2014-08-27 15:08:03
您正在使用jQuery,请阅读文档? – adeneo 2014-08-27 15:16:00