I am trying to print a webpage and making some objects invisible for the
print, and then visible again after. But my code does not work :
function PrintInvoice()
{
document.getElementById("Button1").style.visibility = "hidden";
document.getElementById("Button2").style.visibility = "hidden";
window.print();
document.getElementById("Button1").style.visibility = "visible";
document.getElementById("Button2").style.visibility = "visible";
}
Can anybody with good javascript skills help?
Sergey Poberezovskiy - 24 Jul 2007 10:28 GMT
rather than iterating every control on the page that should not be printed,
it is advised to use a separate stylesheet (or style rules) for printing in
which you define certain types with display:none. See
http://www.w3.org/TR/REC-CSS2/media.html for more info
> I am trying to print a webpage and making some objects invisible for the
> print, and then visible again after. But my code does not work :
[quoted text clipped - 13 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Mike P - 24 Jul 2007 10:31 GMT
Found the error - it was simply a matter of calling the function without
braces i.e. PrintInvoice instead of PrintInvoice().
Eliyahu Goldin - 25 Jul 2007 08:29 GMT
There are two javascripts events onbeforeprint and onafterprint that are
good for placing this type of code in. It will make sure that the page
prints correctly regardless of the way how you initiate print, even if the
user clicks the browser's Print button.
And the css idea that the other poster suggested is even better.

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
>I am trying to print a webpage and making some objects invisible for the
> print, and then visible again after. But my code does not work :
[quoted text clipped - 13 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***