Print image with Javascript

Viewed 20332

I want to print image with javascript. So I used this code to open image in new window and print:

win = window.open(img.src,"_blank");
win.onload = function() { win.print(); }

This works fine with the default image file:

<img id="image1" src="myimage.jpg">

But when i replace the default image with image data read from disk:

var fileElem = document.getElementById("fileElem").files[0];
var reader = new FileReader();
reader.onload = function(event) {
   img.src = event.target.result;
};
reader.readAsDataURL(fileElem); 

And then open new window & print - the image apears fine in the new window, but no print operation is done. How to make the win.print() to work?

2 Answers
Related