最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Javascript printing a popup window works in FirefoxChrome but not Internet Explorer - Stack Overflow

programmeradmin2浏览0评论

The following lines of code create an html page in a browser popup and then prints the popup for the user:

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. However, in IE, no print dialog is displayed. Any suggestions?

I've also tried closing the popup after calling print(), as others have suggested fixes the issue:

function printPage(htmlPage)
{
   var w = window.open("about:blank");
   w.document.write(htmlPage);
   w.print();
   w.close();
}

To no avail.

The following lines of code create an html page in a browser popup and then prints the popup for the user:

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. However, in IE, no print dialog is displayed. Any suggestions?

I've also tried closing the popup after calling print(), as others have suggested fixes the issue:

function printPage(htmlPage)
{
   var w = window.open("about:blank");
   w.document.write(htmlPage);
   w.print();
   w.close();
}

To no avail.

Share Improve this question asked Sep 9, 2011 at 14:08 KyleKyle 4,2381 gold badge36 silver badges42 bronze badges 2
  • What did the Developer Console tell you? – Lightness Races in Orbit Commented Sep 9, 2011 at 14:10
  • Weird; on IE8 the function exists under w and no error is thrown when invoking it, but nothing happens. – Lightness Races in Orbit Commented Sep 9, 2011 at 14:20
Add a ment  | 

1 Answer 1

Reset to default 8

close() the document before you try to print().

function printPage(htmlPage) 
{ 
   var w = window.open("about:blank"); 
   w.document.write(htmlPage);
   w.document.close();
   w.print(); 
} 

Works in IE9.

发布评论

评论列表(0)

  1. 暂无评论