Parag
Parag

Reputation: 4812

javascript to print contents of only specific <div>

I have tried javascript window.print() It prints the full page content including the print button on the page.

Upvotes: 7

Views: 17954

Answers (2)

Michael
Michael

Reputation: 76

Create an iframe and copy your text into it. then you can call the print-function of this, in the iframe embedded window

or

see: String.print()

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176956

You require to create new style sheet print.css and set CSS media=print

for example :

<style media="screen">
  .noPrint{ display: block; }
  .yesPrint{ display: block !important; }
</style>

<style media="print">
  .noPrint{ display: none; }
  .yesPrint{ display: block !important; }
</style>

for more detail : Print a doument with CSS

Upvotes: 19

Related Questions