After successfully printing the content of a div on click, I encounter the issue that none of my jQuery events work after canceling the print preview. This seems to happen without requiring a page refresh.
I'm puzzled as to why this occurs and would like to avoid having to refresh the page post-print preview.
Here is the JavaScript code snippet responsible for handling the print functionality:
$('.btn li:nth-child(1) > a').on("click", function(e){
var divElements = document.getElementById("divContentId").innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<html><head><title>Print Title</title></head><body><table width='670'><tr><td><h1>This is Print Preview Title</h1>" + divElements + "</td></tr></table></body>";
setTimeout(function() {
window.print();
document.body.innerHTML = oldPage;
window.close();
return true;
}, 250);
$(".btn-options").hide(); // The event following the cancelation of the print preview does not trigger and other events fail to work
});