Print specified image on button click

Hi to all , I have a problem in my javascript code. I want to print specified image in my website by clicking the button

here is my code. whats wrong , i cant figure out whats going on …

function printImg() {
  popup =;
popup.focus(); //required for IE

You were not carrying the image over to the popup.

This works:

	<style type="text/css">
	button {

img { width: 200px;}
<p> Print image solution from</p>
<img id="imagehtml" src="imgs/480x480.jpg" alt=""> // substitute with your image path here and the next line  
<a href="#" onclick="PrintImage('imgs/480x480.jpg'); return false;"><button id="printImage">Print this Image</button></a>
function ImagetoPrint(source) {
    return "<html><head><script>function step1(){\n" +
            "setTimeout('step2()', 10);}\n" +
            "function step2(){window.print();window.close()}\n" +
            "</scri" + "pt></head><body onload='step1()'>\n" +
            "<img src='" + source + "' /></body></html>";
function PrintImage(source) {
    Pagelink = "about:blank";
    var pwa =, "_new");;

Hey StevenHu The concatenation of the HTML tags makes me confuse at first and I’ve try to analyze it and i’ve got the right idea … It’s works Thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.