I am using following code but it is not working. It
url = "http:www.google.com/img/1.jpg"
popup = window.open();
popup.document.write(url);
popup.print();
Any other approach?
I am using following code but it is not working. It
url = "http:www.google.com/img/1.jpg"
popup = window.open();
popup.document.write(url);
popup.print();
Any other approach?
Load your image inside img tag with some parent div and then print the div. The example is as follows:
More on print a div can be found here Print a div content using Jquery
var url = "https://mediaserver.goepson.com/ImConvServlet/imconv/9b7d08e02138222989a0f61975f424e1bf046300/original?use=productpictures&assetDescr=google-cloud-print_690x460"
$('#prinatabbleDiv').append("<img src='" + url + "' onload='iamready()'>");
function iamready() {
console.log('ready to print');
//$("#prinatabbleDiv").print();
printDiv("prinatabbleDiv")
}
function printDiv(id) {
var divToPrint = document.getElementById(id);
var newWin = window.open('', 'Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</body></html>');
newWin.document.close();
setTimeout(function() {
newWin.close();
}, 10);
}
#prinatabbleDive {
width: 100vw;
height: 100vh;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='prinatabbleDiv'></div>