简体   繁体   English

Javascript打印弹出窗口适用于Firefox / Chrome但不适用于Internet Explorer

[英]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.

相关问题 javascript脚本可在Firefox,Chrome,Safari,Internet Explorer &lt;9,而不是IE 9中运行 - javascript script works in Firefox, Chrome, Safari, Internet Explorer < 9, but not in IE 9 JS幻灯片可以在Firefox和Chrome上运行,但不能在Internet Explorer上运行吗? - JS slideshow works on firefox and chrome but not internet explorer? 网站可以在Firefox和Chrome中运行,但不能在Internet Explorer中运行 - Site works in Firefox and Chrome but not Internet Explorer 使用Chrome打开Internet Explorer / Firefox等窗口 - Open a Internet explorer/Firefox etc window with Chrome Ecmascript / Javascript可与Internet Explorer一起使用,但不能与FireFox一起使用,为什么? - Ecmascript/Javascript works with Internet Explorer but NOT FireFox Why? Javascript代码段无法在Chrome中运行,但可在Internet Explorer中使用 - Javascript snippet not working in Chrome, but works in Internet Explorer Ajax响应中的javascript在Firefox,Chrome,Opera中有效,但不能在Internet Explorer 11中运行-对象不支持此属性或方法 - javascript in ajax response works in Firefox, Chrome, Opera BUT NOT internet explorer 11 - Object does not support this property or method 这个用于编辑图像的javascript弹出框可在Firefox和chrome中使用,但在Internet Explorer中不会显示弹出框 - this javascript pop up box for edit images works in firefox and chrome but not shows pop up box in Internet explorer JavaScript警报在Firefox上正常运行,但在Chrome和Explorer中不起作用 - JavaScript alert works normally Firefox, but not in Chrome and Explorer 在Chrome中工作,但在Internet Explorer中不工作 - Works in Chrome but not in Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM