Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 901
Parag Avatar asked Jun 02 '10 05:06

Parag


People also ask

How do I print a particular section in JavaScript?

JavaScript Code: You can use this function for print a specific area of web page or full web page content. Use printPageArea() function on onclick event of print button element and provide the content area div ID which you want to print.

How do I print a specific content in HTML?

One of those solutions are: I can keep this HTML content in a div and make it display: to print, but display: none to screen. All other elements on the webpage can be made to display: none for print and display: for the screen. And then call to print.

What is @media print?

Print media is one of the oldest and basic forms of mass communication. It includes newspapers, weeklies, magazines, monthlies and other forms of printed journals. A basic understanding of the print media is essential in the study of mass communication.


2 Answers

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

like image 113
Pranay Rana Avatar answered Sep 26 '22 03:09

Pranay Rana


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()

like image 39
Michael Avatar answered Sep 24 '22 03:09

Michael