I have a page that displays a table with a lot of stats. I want to create a print button which will let the user print the stats without having to print the rest of the page.
It seems the best thing to do would be to create a pop-up window which generates a more printer-friendly version of the stats, and then calls the window.print() function.
Creating a popup window is somewhat problematic however. When I write to the new window using document.write(), the pop-up window appears but starts loading endlessly on Firefox. On IE this doesn't happen. Secondly, trying to print the new window doesn't work at all on IE, but works on FF.
Here's the code:
function printWindow() {
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
newwindow.document.write("<h1>Test</h1>");
newwindow.print();
}
Is there a way to get consistent cross-browser behavior here?
I will paste a sample in few minutes.
you open a pop up and set the CSS using medai and create CSS for printing.