Whing Dela Cruz
asked on
Div print
Hi Experts, I'm using the code below to print data in div. However, I noticed that the approached would open other window and that be able to show other page to print or to save. My problem is that I could no longer run my web site once this window will not close. This Untitled page would stop me from re-running my site. Is there anyone who can explain me why this thing is happen? What's the solution to prevent this problem? Thanks!
function printData(id){
var divToPrint = document.getElementById('Prolist-A34');
newWin= window.open();
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
ASKER
Hi Julian, In my case when i run the code and open for printing the page it will works fine. However, when I'm back the original page without closing the window of printing and refresh the original page, that's the problem. I can't refresh the original page while the two pages are open. Is there a way to prevent this?
I suspect the reason you can't refresh is because there is a print in progress. The newWin.print() is loading a modal print dialog that needs to be closed before you can do anything in the original window.
ASKER
Hi Julian, Do you have some example of media="print"? Can you give some ideas how to start with? Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you sir!
You are welcome.
If I run your code a window opens - the document prints, the window closes and I am back to the original page - I can repeat this as often as I want.
I am not sure what you mean by you "can no longer run your website" - we probably need to see more code or a link.
Having said that
Why not just create a style sheet with media="print" and hide the elements you don't want in your printout.
You specify the stylesheet like this
Open in new window
In the stylesheet you use classes to hide those elements you don't want visible when you print.