how to use callback in window.print ()

0

Well I created a jQuery print function, when it runs it hidden from the menu div and prints the page. It works perfectly, but in some browser like IE and the iPhone safari it does not work.

I noticed that the error occurs because of the function of displaying the menu again after printing. I think one way to solve this is to have the menu displayed in the print callback. Does anyone know how to do this?

Follow the code:

        /* Função para imprimir */
        function imprimir() {

            // Remove Menu topo
            $(".header").hide();
            $(".sidenav").hide();
            $(".shadow-full").hide();
            $(".relatorio caption").show();
            $('body').css({"padding-top": "0px"});

            // Imprime a página
            window.print();

            // Adiciona Menu topo
            $(".relatorio caption").hide();
            $(".header").show();
            $('body').css({"padding-top": "40px"});
        }
    
asked by anonymous 07.02.2017 / 17:57

1 answer

1

Try only with css

@media print
{    
    .no-print
    {
        display: none;
    }
  
    .print-only {
  
    display: inline;
    
    }
  
}

@media screen {
.print-only {
display: none;}
  }
<div class="no-print">
  Só aparece na tela
  
</div>

<div class="print-only">

  Aparece só na impressão
  
</div>

<div>

  Aparece em ambos os casos
  
</div>

<input type="button" value="imprimir" onclick="window.print();" />
    
07.02.2017 / 19:30