print html generated by functions to printer? - Javascript DOM

Javascript examples for DOM:Element removeChild

Description

print html generated by functions to printer?

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// w  ww . ja  v  a  2s  .c  om
var someHtml = '<a href="">a</a>';
var i = document.createElement('iframe');
i.onload = function() {
    i.contentDocument.body.innerHTML = someHtml;
    i.contentWindow.print();
    setTimeout(function() {
        document.body.removeChild(i);
    }, 0);
};
document.body.appendChild(i);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials