Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

450
Vistas
Back button stop working after window.print()

I have a modal with two buttons: print and close modal

html:

   <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <button class="header__print button--print" title="Print" onclick="printDiv('exportContent')"></button>
                    </div>

JS:

<script type="text/javascript">
function printDiv(divID) {
   var divElements = document.getElementById(divID).innerHTML;
   var oldPage = document.body.innerHTML;
   
   document.body.innerHTML = 
     "<html><head><title></title></head><body>" + 
     divElements + "</body>";

   window.print();

   document.body.innerHTML = oldPage;
}
</script>

The issue appears when I press on print btn and close print screen, then back (close) button stop working.

Any idea why is it happening? thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

By replacing the entire content of the body, you remove the registered eventListeners. I guess you had an eventListener for the click on "close" button, so the click is no longer listened, and it would be quite difficult to "reconnect" all the events.

To display specific content for print, I advise you not to touch the DOM, and to manage it only with a specific style sheet :

@media print {
  section {
    display: none;
  }
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda