Skip to content Skip to sidebar Skip to footer

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:

  1. Open new window using window.open.
  2. Write to it the img tag.
  3. Once the image was loaded, print the document using window.print().
  4. 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>

http://jsbin.com/qaruze/edit?html,js

Post a Comment for "Print Button To Print A Attached Image"