function printpage() {document. getElementById ...">

Why does he print only once? Please give me a solution

<html> <head> <script type="text/javascript"> function printpage() {document. getElementById ('print').style.display='none'; window.print() } </script> </head> <body> <td align="center"> <input name="print" type="submit" id="print" value="PRINT" onclick="printpage()" /> </td> </body> </html> 

When I click, it will open the print window. As soon as I close the print window and open it again, and then click on print without restarting, then this will not work.

+1
source share
3 answers

Remove document.getElementById('print').style.display='none'; from your printpage() function.

In the above example, the button will be visible to another click event, but when you print the document, the button will be shown on the printed document. I'm right?

In order not to print the print button, you need to use css media queries @media print

Add an externernel or the <style> tag inside the <head> tag of the HTML page in your stylesheet:

  @media print { .noprint { display: none; } }​ 

and add the .noprint class to

 <input name="print" class="noprint" type="submit" id="print" value="PRINT" onclick="printpage()" /> 

WATCH DEMO

It will print the document without printing a button, and your button will also be visible a second time :-)

Edition:

USE HTML HOW TO GIVE BELOW:

 <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> <!-- Your Stylesheet (CSS) --> <style type="text/css"> @media print { .noprint { display: none; } }​ </style> <!-- Your Javascript Function --> <script> function printpage() { window.print(); } </script> </head> <body> <!-- Your Body --> <p>Only This text will print</p> <!-- Your Button --> <input class="noprint" type="button" value="PRINT" onclick="printpage()" /> </body> </html> 

SEE ABOVE CODE IN ACTION

+7
source

Change type = send to type = button

You unload the page when sending

And hide the button with CSS as sent by AK

+1
source

Just uninstall

 document.getElementById('print').style.display='none'; 

from your printpage() function. It will work fine

If you do not want the print button on the printed page,

 document.getElementById('print').style.visibility='hidden' window.print(); document.getElementById('print').style.visibility='visible' 
0
source

Source: https://habr.com/ru/post/950695/


All Articles