如何使用JavaScript使用数据打开新的打印对话框 [英] how to open new print dialog with data using javascript
问题描述
我想用现有数据打开新的打印对话框.我写了以下代码
i want to open new print dialog with existing data. i write follwing code
print: function (dialog) {
var printW = window.open("");
var d = $("#" + dialog);
var html = "<link href='" + baseURL + "Content/Styles/ui-lightness/jquery-ui.min.css' rel='stylesheet'/><link href='" + baseURL + "Content/Styles/ui-lightness/jquery.ui.theme.css' rel='stylesheet'/><link type=\"text/css\" rel=\"stylesheet\" href=\"" + baseURL + "Content/Styles/Site.css\">";
html += "<div class=\"ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable\" style=\"outline: 0px none; z-index: 1002; position: absolute; height: auto; width: 800px; display: block;\" role=\"dialog\" aria-labelledby=\"ui-id-1\">";
html += "<div id=" + dialog + " class=\"inner ui-dialog-content ui-widget-content\" style=\"width: auto;height:auto;\" scrolltop=\"0\" scrollleft=\"0\">";
d.find(".buttons").hide();
html += d.html();
html += "</div>";
printW.document.write(html);
printW.document.close();
printW.focus();
printW.print();
d.find(".buttons").show();
printW.close();
}
上面的代码对于Internet Explorer来说是正确的,但不适用于chrome浏览器.
该行发生错误
printW.document.write(html);
错误是:PrintW的未定义类型文档.
请帮助
正确的pre
标签.
[/Edit]
the above code working correct for Internet Explorer but it''s not working with chrome browser.
error occurred for this line
printW.document.write(html);
and error is: undefined type document for PrintW.
please help
Correct pre
tags.
[/Edit]
推荐答案
(" +对话框); var html = " + baseURL + " + baseURL + Content/Styles/ui- lightness/jquery.ui.theme.css'rel ='stylesheet'/><链接类型= \文本/css \" rel = \样式表\" href = \" + baseURL + " ; html + = " ; html + = " +对话框+ " ; d.find("
("#" + dialog); var html = "<link href='" + baseURL + "Content/Styles/ui-lightness/jquery-ui.min.css' rel='stylesheet'/><link href='" + baseURL + "Content/Styles/ui-lightness/jquery.ui.theme.css' rel='stylesheet'/><link type=\"text/css\" rel=\"stylesheet\" href=\"" + baseURL + "Content/Styles/Site.css\">"; html += "<div class=\"ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable\" style=\"outline: 0px none; z-index: 1002; position: absolute; height: auto; width: 800px; display: block;\" role=\"dialog\" aria-labelledby=\"ui-id-1\">"; html += "<div id=" + dialog + " class=\"inner ui-dialog-content ui-widget-content\" style=\"width: auto;height:auto;\" scrolltop=\"0\" scrollleft=\"0\">"; d.find(".buttons").hide(); html += d.html(); html += "</div>"; printW.document.write(html); printW.document.close(); printW.focus(); printW.print(); d.find(".buttons").show(); printW.close(); }
上面的代码对于Internet Explorer来说是正确的,但不适用于chrome浏览器.
该行发生错误
printW.document.write(html);
错误是:PrintW的未定义类型文档.
请帮助
正确的pre
标签.
[/Edit]
the above code working correct for Internet Explorer but it''s not working with chrome browser.
error occurred for this line
printW.document.write(html);
and error is: undefined type document for PrintW.
please help
Correct pre
tags.
[/Edit]
演示- [Demo]窗口打开并打印预览 [ ^ ].
在此演示中,我删除了所有相关代码,并尝试在Div
中打印 Hello World ,它运行良好.您可以检查.
因此,我的建议是,查看 Developer Tool Console (类似于FireFox
中的FireBug
控制台),并找出是否列出了任何错误.如果列出了,请更正它们.
Demo - [Demo] Window Open and Print Preview[^].
In this demo, I removed all the dependent codes and just tried to print Hello World in theDiv
and it is working perfectly. You can check.
So, my suggestion to you is that, look at the Developer Tool Console (likeFireBug
console inFireFox
) and find out whether any errors are listed or not. If listed, then correct them.
这篇关于如何使用JavaScript使用数据打开新的打印对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!