Derin
Derin

Reputation: 1230

Window with Image - Print() Issue in Chrome

I am printing a document by opening a new window and using .print() function.

Document has images also. But in chrome, it prints without images.

Added some delay to finish loading images before printing [setTimeout], but didn't helped. its printing half of the image.

       function PrintContent() {
                var DocumentContainer = document.getElementById(rClientID);
                var WindowObject = window.open('', "PrintOrder",
                          "width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
                WindowObject.document.open();
                WindowObject.document.writeln(DocumentContainer.innerHTML);
                WindowObject.document.close();
                WindowObject.focus();
                WindowObject.print();
                //WindowObject.close();
                return false;
        }

Upvotes: 1

Views: 2325

Answers (2)

jlerma
jlerma

Reputation: 71

The solution is to add the onLoad event to body tag:

 WindowObject.document.write('<html><header><title></title></header>');
 WindowObject.document.write('<body onLoad="self.print(); self.close()">');
 WindowObject.document.write(DocumentContainer.innerHTML);
 WindowObject.document.write('</body></html>');

Upvotes: 0

Derin
Derin

Reputation: 1230

Modified the printing line, printing window object on onload-event,

supposed to call only after loading the page.

seems to be working fine.

WindowObject.onload = function() { WindowObject.print() };

Upvotes: 3

Related Questions