Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

js window.open then print()

print() doesn't work in IE after opening a new window. It works in Chrome. Here's a tester:

<html> <head> <script type="text/javascript">   function openWin()   {     myWindow=window.open('','','width=200,height=100');     myWindow.document.write("<p>This is 'myWindow'</p>");     myWindow.focus();     myWindow.print(); //DOES NOT WORK   } </script> </head> <body>  <input type="button" value="Open window" onclick="openWin()" />  </body> </html> 
like image 254
Clive Avatar asked Mar 24 '12 13:03

Clive


People also ask

What does window print () do in JavaScript?

print() Opens the print dialog to print the current document. If the document is still loading when this function is called, then the document will finish loading before opening the print dialog.

Can I set the window print settings with JavaScript?

The window. print() method calls the browser's build in print support plugin to print the current DOM page. you can check the documentation, it doesn't support any argument or settings. to setup the print, you can only utilize the browser's GUI( ex. enable or disable background graphics etc.)

How do I get a return value from a Windows Open?

Typically the onclick event on the "Yes" or "Ok" button in the modal dialog looks like this: window. returnValue = true; window. close();


2 Answers

checkout: window.print() not working in IE

Working sample: http://jsfiddle.net/Q5Xc9/1/

like image 129
Turgut Avatar answered Sep 29 '22 19:09

Turgut


Turgut gave the right solution. Just for clarity, you need to add close after writing.

function openWin()   {     myWindow=window.open('','','width=200,height=100');     myWindow.document.write("<p>This is 'myWindow'</p>");       myWindow.document.close(); //missing code       myWindow.focus();     myWindow.print();    } 
like image 22
Osa E Avatar answered Sep 29 '22 19:09

Osa E