I have a webpage with several divs. User should be able to print one div (selected content) or the entire page. If the users prints the entire page it should maintain the header, footer, etc. I can make it print either one section or the entire page, but I can’t figure out how to do both gracefully. My current css is using the @media print like so:
@media print
{
body * { visibility: hidden; }
.printArea * { visibility: visible; }
}
Using jQuery, I added the class printArea to the selected section and then called window.print().
$("a.printSection").live("click", function(){
//the id of the sectionToPrint is actually passed in via metadata plug-in
$("div#sectionToPrint").addClass('printArea');
window.print();
});
I have tried adding and removing a class to the body but the issue is that jQuery removes the class name before the job actually prints. Any ideas on how I could print a section or the entire page? The true problem comes in when you print a section and then use ctrl + p to print.
Thanks in advace!
First of all, you should separate the content from header and footer. Use the following code to see the working example:
I hope this helps.