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.
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()" /> 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> 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'