Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aareyes00's avatar

window.print not working after clicking once

Hi. I have a print page button but it's not working after clicking once. This is my code


$('body').css('overflow', 'hidden');
$('html').animate({ scrollTop: 0 }, 'fast', 'swing', function () {
  var printContents = document.getElementById("shipping-reservation-
  summary").innerHTML;     
  var originalContents = document.body.innerHTML;       
  document.body.innerHTML = printContents;      
  window.print();      
  document.body.innerHTML = originalContents;
  return false;
})
0 likes
8 replies
tykus's avatar

Why are you replacing the entire document body?

Snapey's avatar

You probably break the button when you overload the contents

tykus's avatar

Don't replace the entire contents of the <body>. You should be able to reuse the same markup for both screen and print styles.

aareyes00's avatar

@tykus I already remove it but still not working. After clicking the print button when I try again, it's not working anymore

tykus's avatar

Can you post your entire template and JS?

Please or to participate in this conversation.