Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > hiding, showing and printing in javascript

Reply
Thread Tools

hiding, showing and printing in javascript

 
 
Mike P
Guest
Posts: n/a
 
      07-24-2007
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.visibilit y = "hidden";
document.getElementById("Button2").style.visibilit y = "hidden";

window.print();

document.getElementById("Button1").style.visibilit y = "visible";
document.getElementById("Button2").style.visibilit y = "visible";
}

Can anybody with good javascript skills help?



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
Guest
Posts: n/a
 
      07-24-2007
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

"Mike P" wrote:

> 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.visibilit y = "hidden";
> document.getElementById("Button2").style.visibilit y = "hidden";
>
> window.print();
>
> document.getElementById("Button1").style.visibilit y = "visible";
> document.getElementById("Button2").style.visibilit y = "visible";
> }
>
> Can anybody with good javascript skills help?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
 
 
 
Mike P
Guest
Posts: n/a
 
      07-24-2007
Found the error - it was simply a matter of calling the function without
braces i.e. PrintInvoice instead of PrintInvoice().



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      07-25-2007
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Mike P" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.visibilit y = "hidden";
> document.getElementById("Button2").style.visibilit y = "hidden";
>
> window.print();
>
> document.getElementById("Button1").style.visibilit y = "visible";
> document.getElementById("Button2").style.visibilit y = "visible";
> }
>
> Can anybody with good javascript skills help?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 2 11-27-2010 12:12 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:52 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments