I want to print an image using javascript. Therefore, I used this code to open the image in a 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 a new window and print - the image will appear in a new window, but the print operation is not performed. How to make win.print () work?
source
share