Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

448
Views
El botón Atrás deja de funcionar después de window.print ()

Tengo un modal con dos botones: imprimir y cerrar 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>

El problema aparece cuando presiono imprimir btn y cierro la pantalla de impresión, luego el botón Atrás (cerrar) deja de funcionar.

¿Alguna idea de por qué está sucediendo? ¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Al reemplazar todo el contenido del cuerpo, elimina los eventListeners registrados. Supongo que tenía un eventListener para hacer clic en el botón "cerrar", por lo que el clic ya no se escucha y sería bastante difícil "reconectar" todos los eventos.

Para mostrar contenido específico para imprimir, le aconsejo que no toque el DOM y que lo administre solo con una hoja de estilo específica:

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!