¿Por qué se imprime sólo una vez? por favor dame solucion

<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 a print window. Once I close print window and open it again and then click on print, without reloading, then it will not work.

preguntado el 31 de julio de 12 a las 11:07

What is it that you're trying to attain? -

Please take the time to format your code and properly space it. We should not have to labour to read your code. If you can't be bothered to even put line breaks in, why should anyone help? -

Wondering how you clicked on the print button again if it was hidden? -

First, there is no PHP involved in this isse (wrong tag). Second, as Ashwin said, how did you click the print button a second time since it is being hidden after the frist click? Did you mean that you can't find the button after you clicked it? That's because it's hidden. Solution: add document.getElementById('print').style.display='block'; después de window.print(); -

@user1500506: see my answer having solution with css media queries. -

3 Respuestas

Elimine document.getElementById('print').style.display='none'; a partir de su printpage() función.

In the above case the button will be visible for another click event but when you will print the document, the button will be shown on printed document. Am I right?

To prevent printing the print button you need to use consultas de medios css @media print

Add following in your extrernal stylesheet OR in <style> etiqueta dentro de un <head> tag of the HTML page:

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

y añade .noprint clase en

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

VER DEMO

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

EDITADO:

USE HTML AS GIVEN 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

Respondido 01 ago 12, 05:08

@M2K: what you have tried? create a fiddle on jsfiddle.net or jsbin.com - Ahsan Khurshid

@M2K: I have updated my answer with an HTML code, just copy paste the html in a blank html document, ant try. It will definitely work. - Ahsan Khurshid

Change type=submit to type=button

You are unloading the page when submitting

And hide the button with CSS as posted by Alaska

contestado el 23 de mayo de 17 a las 12:05

You are not giving enough information, someone already asked: how could you print again when you button disappeared. So tell us exactly what you do step by step and if there are other scripts on the page. Even better: give use the URL of a test page - mplungjan

Solo quitar

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

a partir de su printpage() function. It'll work fine

If you don't want the print button on your printed page,

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

Respondido 31 Jul 12, 12:07

This will lead to the print button being printed, too. - mido

@MiDo Ya i know, but he wants to print it again . And if he doesn't want to see that button, your solution suits best - Bhuvan Rikka

+1. It might be best to create a stylesheet for printing that doesn't show the button. - Ynhockey

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.