imageshark
asked on
using jquery to print a section of a page
Is there a way, using jquery, to print a "section" of a page.
for instance, I have a game schedule in a table. The table is surround by a div called "printarea".
How do I click a printer icon, and the div "printarea" is sent to the printer.
So just the schedule prints, not the entire page, and background, etc...
for instance, I have a game schedule in a table. The table is surround by a div called "printarea".
How do I click a printer icon, and the div "printarea" is sent to the printer.
So just the schedule prints, not the entire page, and background, etc...
All that normally does is ask the browser to print the page. What you can do is put the schedule in an iframe and then put the print button in the iframe and print the iframe.
Or... I have one page where a calendar is included from a separate file. I have button to open only the calendar in the browser to print it.
ASKER
I found that, and I'm trying it, but I can't seem to get it to work.
check your browser's error console. What does it say?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a simple way to just print the content
function printDiv(id) {
var html = document.getElementById(id).innerHTML;
// var html = $("#"+id).html(); // jQuery version
var w = window.open('','_blank');
w.document.write('<link href="stylesheet.css" rel="stylesheet"/><body onload="window.focus(); window.print">'+html+'</body>');
w.document.close();
}
ASKER
Solution is working!