Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<img src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/print-128.png"  onclick="newWindow('http://upload.wikimedia.org/wikipedia/commons/5/5b/Ultraviolet_image_of_the_Cygnus_Loop_Nebula_crop.jpg')">
</body>
</html>
 
function newWindow(src){
 
  win = window.open("","","width=600,height=600");
    var doc = win.document;
    // init head
    var head = doc.getElementsByTagName("head")[0];
    // create title
    var title = doc.createElement("title");
    title.text = "Child Window";
    head.appendChild(title);
    // create script
    var code = "function printFunction() { window.focus(); window.print(); }";
    var script = doc.createElement("script");
    script.text = code;
    script.type = "text/javascript";
    head.appendChild(script);
    // init body
    var body = doc.body;
    //image
    doc.write('<img src="'+src+'" width="300">');
  
    //chrome
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
    
      win.printFunction();               
    } else {
        win.document.close();
        win.focus();
        win.print();
        win.close();
    }
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers