views:

49

answers:

1

Hi all,

I have the following function.

<script type="text/javascript">
     window.onbeforeprint = expandAll;

     function expandAll(){
       $(".fieldset:gt(0)").slideDown("fast");
      }
</script>

For this html

<table class="sectionHeader" ><tr ><td>Heading</td></tr></table>
 <div style="display:none;" class="fieldset">Content</div>

I have several block of content over the page, but when I do print preview or print, I can see all divs sliding down before opening the print preview or printing but on the actual print preview or print out they are all collapse.

Anyone have any idea why is this?

Thanks.

+2  A: 

You need to use a print style sheet e.g.

<link href="/css/print.css" rel="stylesheet" type="text/css" media="print"/>

You can style things up specifically for how you want the printed page to look without having to use the JS to do anything to it.

matpol
Despite That did not work either, that was not the question, as I use onbefore print before and it work, for some reason the use of jquery on onbefore print creates a conflict and that was the question about, why is this and how to fix it. Thanks.
Cesar Lopez
I think the way printing works is it basically reloads the page so what you see in the print view is the default which I guess is with the panels closed. If you set up a print style sheet defining the panels as open then the panels will be open when you print them. In fact by default they should display as open and you should close then as the JS initiates to avoid any usability/accessibly issues.
matpol