Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After print function not able to click other tabs

I am using a default print function for printing, but once print function is completed i am not able to click other tabs. Print window is opening in the same page

function printReport() {
    var divElements = $('.nicEdit-main').html();
    var oldPage = document.body.innerHTML;
    document.body.innerHTML = "<html><head><title></title></head><body>" + divElements + "</body>";
    window.print();
    document.body.innerHTML = oldPage;
}
like image 458
Prashobh Avatar asked May 10 '13 08:05

Prashobh


People also ask

What does Window print () return?

The print() method prints the contents of the current window.


1 Answers

Unfortunately, you just replaced the entire body of your page. innerHTML only returns a string form of the HTML minus the handlers and any data attached to the elements. Setting the innerHTML recreates the DOM from that string without the handlers that were originally attached. You just "effectively" paralyzed the page!

I suggest:

  • The hard way would be to continue what you are doing, but delegate all handlers to document like how live would have done it so that they won't be removed. Hard, possible, but not scalable, maintainable or optimal.

  • Or you could just create a hidden iframe and place your content to be printed there. Then call print from that iframe window instead. That way, you won't lose your current page.

  • Others would create a new window, put content there, run print and close it immediately after. Works the same as iframes, but you wouldn't want a creepy window that opens and closes immediately like some pop-up ad.

like image 78
Joseph Avatar answered Sep 28 '22 06:09

Joseph