Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: userc865b
Added: Jun 13, 2018 6:40 AM
Modified: Jun 13, 2018 6:48 AM
Views: 16
Tags: js
  1. function printPageArea(areaID){
  2.     var printContent = document.getElementById(areaID);
  3.     var WinPrint = window.open('', '', 'width=900,height=650');
  4.     WinPrint.document.write(printContent.innerHTML);
  5.     WinPrint.document.close();
  6.     WinPrint.focus();
  7.     WinPrint.print();
  8.     WinPrint.close();
  9. }
  10.  
  11. function printout() {
  12.  
  13.     var newWindow = window.open();
  14.     newWindow.document.write(document.getElementById("output").innerHTML);
  15.     newWindow.print();
  16. }
  17.  
  18.  
  19. // EXAMPLE https://stackoverflow.com/questions/1071962/how-do-i-print-part-of-a-rendered-html-page-in-javascript/1072151#1072151
  20. // https://stackoverflow.com/questions/1071962/how-do-i-print-part-of-a-rendered-html-page-in-javascript/1072151#1072151
  21. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  22. <head>
  23.     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  24.     <title>Print Portion Example</title>
  25.     <style type="text/css">
  26.         @media print {
  27.             body * {
  28.                 display:none;
  29.             }
  30.  
  31.             body .printable {
  32.                 display:block;
  33.             }
  34.         }
  35.     </style>
  36.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  37. </head>
  38.  
  39. <body>
  40. <h1>Print Section Example</h1>
  41. <div id="div1">Div 1</div>
  42. <div id="div2">Div 2</div>
  43. <div id="div3">Div 3</div>
  44. <div id="div4">Div 4</div>
  45. <div id="div5">Div 5</div>
  46. <div id="div6">Div 6</div>
  47. <p><input id="btnSubmit" type="submit" value="Print" onclick="divPrint();" /></p>
  48. <script type="text/javascript">
  49.     function divPrint() {
  50.         // Some logic determines which div should be printed...
  51.         // This example uses div3.
  52.         $("#div3").addClass("printable");
  53.         window.print();
  54.     }
  55. </script>
  56. </body>
  57. </html>