[英]Javascript printing a popup window works in Firefox/Chrome but not Internet Explorer
The following lines of code create an html page in a browser popup and then prints the popup for the user: 以下代码行在浏览器弹出窗口中创建一个html页面,然后为用户打印弹出窗口:
function printPage(htmlPage)
{
var w = window.open("about:blank");
w.document.write(htmlPage);
w.print();
}
This code successfully opens a print dialog in both Firefox and Chrome. 此代码在Firefox和Chrome中成功打开了一个打印对话框。 However, in IE, no print dialog is displayed.
但是,在IE中,不显示打印对话框。 Any suggestions?
有什么建议么?
I've also tried closing the popup after calling print(), as others have suggested fixes the issue: 我也尝试在调用print()后关闭弹出窗口,正如其他人建议修复问题一样:
function printPage(htmlPage)
{
var w = window.open("about:blank");
w.document.write(htmlPage);
w.print();
w.close();
}
To no avail. 无济于事。
close()
the document
before you try to print()
. 在尝试
print()
之前close()
document
。
function printPage(htmlPage)
{
var w = window.open("about:blank");
w.document.write(htmlPage);
w.document.close();
w.print();
}
Works in IE9 . 适用于IE9 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.