Print Button To Print A Attached Image
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?
Solution 1:
- Open new window using
window.open
. - Write to it the
img
tag. - Once the image was loaded, print the document using
window.print()
. - Close the window using
window.close()
You can do this with code like this:
functionprintImg(url) {
var win = window.open('');
win.document.write('<img src="' + url + '" onload="window.print();window.close()" />');
win.focus();
}
<imgsrc="http://i.stack.imgur.com/hCYTd.jpg" /><buttononclick="printImg('http://i.stack.imgur.com/hCYTd.jpg')">Print</button>
Post a Comment for "Print Button To Print A Attached Image"