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>
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.
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.)
Typically the onclick event on the "Yes" or "Ok" button in the modal dialog looks like this: window. returnValue = true; window. close();
checkout: window.print() not working in IE
Working sample: http://jsfiddle.net/Q5Xc9/1/
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With