I would like to add a print button in my webpage. upon clicking the print icon, it should automatically start print the attached image
How can i achieve this?
window.open
.img
tag.window.print()
.window.close()
You can do this with code like this:
function printImg(url) {
var win = window.open('');
win.document.write('<img src="' + url + '" onload="window.print();window.close()" />');
win.focus();
}
<img src="http://i.stack.imgur.com/hCYTd.jpg" />
<button onclick="printImg('http://i.stack.imgur.com/hCYTd.jpg')">Print</button>
http://jsbin.com/qaruze/edit?html,js