Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <script type="text/javascript">
  2. function PrintDiv(id) {
  3. var data=document.getElementById(id).innerHTML;
  4. var myWindow = window.open('', 'testing', 'height=800,width=1000');
  5. myWindow.document.write('<html><head><title>testing</title>');
  6. /*optional stylesheet*/ //myWindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
  7. myWindow.document.write('</head><body >');
  8. myWindow.document.write(data);
  9. myWindow.document.write('</body></html>');
  10. myWindow.document.close(); // necessary for IE >= 10
  11.  
  12. myWindow.onload=function(){ // necessary if the div contain images
  13.  
  14. myWindow.focus(); // necessary for IE >= 10
  15. myWindow.print();
  16. myWindow.close();
  17. };
  18. }
  19. </script>
  20.  
  21.  
  22. <div id="myDiv">
  23. This will be printed.
  24. <img src="image.jpg"/>
  25. </div>
  26. <div>
  27. This will not be printed.
  28. </div>
  29. <div id="anotherDiv">
  30. Nor will this.
  31. </div>
  32. <input type="button" value="Print Div" onclick="PrintDiv('myDiv')" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement