Printing from a new window is a crazy way to achieve something that is catered for by CSS (from CSS2 if I recall correctly).
Simply specify an @media rule in your CSS style sheet:
<style>
/*
All common (screen) styles here, in the normal way.
*/
@media print {
* { display: none; }/* Hide everything ... */
#mydiv { display: block; }/* ... except the required div */
}
</style>
The 'display' style directive in the print block will override any 'display' directive(s) in the common block. All other directives in the common block that effect #mydiv will be honoured in the print. I think I'm right in saying that this includes any directives inherited by #mydiv from hidden parent elements (eg. body). This is certainly what I would expect, and most likely what you want. If not, then add further directives for #mydiv in the print block.
More information here .
If you need two or more Print buttons, each to print a particular div, then that's a different matter. You would need some javascript, but still not necessary to open a new window. See eg here .
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372