-1
<html>
    <head>
    <style media="print">
       @page 
    {
        size: auto;  
        margin: 0mm;  
    }   
     </style>

        <title></title>
    </head>
    <body onload="window.print()">
       `<div id="sample" >`  
        <p>Line1</p>
        <p>Line2</p>
        <p>Line3</p>
    </div>
     <input type="button" id="print" value="print" />

     <p class="rh"><i>Miranda v. Arizona</i> in Context</p>
     <h2><i>Miranda v. Arizona</i> in Context</h2>

    </body>
</html>

The Output is added in the image.

From this have to remove url, page count, Date from Header and footer Thanks in Advance

Go-vi
  • 1
  • 3

1 Answers1

0

You first have to open the window, then select by its id or class, the element to be shown (for example the outsider div). Aftwards you may want to remove (or hide) some elements, so select them by its id or class, remove them, and then, write it back to the original outsider element to be printed (using JS function innerHTML). It is better to do it in a javascript function, and then call this function.

In other words, lets say you have your html code above. If you want to print the body, and remove the first div (with id "sample") from printing, you may create and invoke the following JS function:

<script>
  function printing(){
   $(document).ready(function(){   
     var bodyPrint = document.getElementsByTagName("BODY")[0]
     var win = window.open(' ', 'popimpr');

     document.getElementById("sample").remove();//Removes the element from printing

     win.document.write( bodyPrint.innerHTML );//Here's what is going to be printed
     win.document.close();
     win.print();
     win.close();
   });
  }
</script>
Mundo
  • 96
  • 7