I want to print using iFrame and javascript.
Below are my sample codes for the same:
Javascript
 function printDiv(divP) {
            window.frames["print_frame"].document.body.innerHTML = $(divP).html();
            window.frames["print_frame"].window.focus();
            window.frames["print_frame"].window.print();
        }
HTML
<iframe name="print_frame" width="0" height="0" frameborder="0" src="about:blank">
        </iframe>
This Code is working in IE and Mozilla only. Other Browsers are printing White pages. I don't want to use the Media Queries. What could be the possible issue?
The solution :
Few changes :  document.write :( and open and close functions) + iframe 1px size..
 function printDiv(divP) {
  window.frames["print_frame"].document.open();
  window.frames["print_frame"].document.write('<body>aaaaaaaa</body>');
  window.frames["print_frame"].document.close();
  window.frames["print_frame"].focus();
  window.frames["print_frame"].print();
        }
printDiv()
http://jsbin.com/eLIQAXU/4/quiet
this is working in FF , chrome,IE ,safari :

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